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,098
  • 1
  • 21
  • 27
kritya
  • 3,242
  • 6
  • 41
  • 59
  • 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
  • 34,863
  • 6
  • 72
  • 90
-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
  • 5,771
  • 6
  • 31
  • 39