0

I am wanting to store some info in array

i declared an array

var added = [];

Question: I want to add a number/string at the last of the array.

And then i want to add all the data to the a dom ?
I am new to js array please help me out with this basic things

Calum
  • 5,308
  • 1
  • 22
  • 27
kritya
  • 3,312
  • 7
  • 43
  • 60
  • Here is similar question that can help refer http://stackoverflow.com/questions/351409/newbie-javascript-appending-to-array – Shadow Aug 09 '11 at 08:57

2 Answers2

1
added.push("123");
added.push("abc");
$('div').html(added.join());

This will set the html of the div to 123,abc

Richard Dalton
  • 35,513
  • 6
  • 73
  • 91
-1
added.push("123");
added.push("abc");
added.push("xyz");

for(i in added)
{
 $("div").append(added[i]);  


}

Hope this helps!

EDIT:

I though you need to assign all one by one!

You could use:

$("div").html(added.join(', '));  

to get things seperated by comma!

linuxeasy
  • 6,269
  • 7
  • 33
  • 40