# Adding to an Array

**URL:** <https://www.ruby-forum.com/t/adding-to-an-array/134787>\
**Category:** Rails\
**Created:** [April 15, 2008, 3:12am UTC](https://www.ruby-forum.com/t/adding-to-an-array/134787 "2008-04-15T03:12:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [April 15, 2008, 3:12am UTC](https://www.ruby-forum.com/t/adding-to-an-array/134787/1 "2008-04-15T03:12:02Z")

</div>

Hello,  
I’ve been looking at the array stuff in the Noobkit, but I can’t seem  
to find how to insert another entry in the array… Pretty much, I’m  
going to be iterating through stuff and catching some things and adding  
them to an array. I want to always add to the end of the array… In  
stuff I’ve seen, you must define an index.

Any suggestions?

Thanks,

- Jeff

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [April 15, 2008, 4:02am UTC](https://www.ruby-forum.com/t/adding-to-an-array/134787/2 "2008-04-15T04:02:13Z")

</div>

@a = Array.new  
@a.push “item1”  
@a \<\< “item2”  
@a.join(",") =\> “item1”, “item2”

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [April 15, 2008, 4:49am UTC](https://www.ruby-forum.com/t/adding-to-an-array/134787/3 "2008-04-15T04:49:08Z")

</div>

that’s not correct. This is what it does:

> > a = Array.new  
> > =\> []  
> > a.push “item1”  
> > =\> [“item1”]  
> > a \<\< “item2”  
> > =\> [“item1”, “item2”]  
> > a.join(“,”)  
> > =\> “item1,item2”

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)  
VIDEO #4 coming soon!  
[http://sensei.zenunit.com/](http://sensei.zenunit.com/)

On 15/04/2008, at 12:02 PM, Nathan E. wrote:

> ## @a = Array.new @a.push “item1” @a \<\< “item2” @a.join(“,”) =\> “item1”, “item2”
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

/

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [April 15, 2008, 5:09am UTC](https://www.ruby-forum.com/t/adding-to-an-array/134787/4 "2008-04-15T05:09:01Z")

</div>

Right, my bad.
