I have a bunch of things I want to add into an array, and I don't know what the size of the array will be beforehand. Can I do something similar to the c# arraylist in javascript, and do myArray.Add(object); repeatedly on it?
views:
205answers:
5
+10
A:
just use array.push();
var array = [];
array.push();
This will add another item to it.
To take one off, use array.pop();
Link to JavaScript arrays: http://www.hunlock.com/blogs/Mastering%5FJavascript%5FArrays
Kevin
2009-11-17 13:16:33
Sweet! I was looking in the wrong direction. Thanks!
SLC
2009-11-17 13:32:50
+2
A:
javascript uses dynamic arrays, no need to declare the size beforehand
you can push and shift to arrays as many times as you want, javascript will handle allocation and stuff for you
knittl
2009-11-17 13:16:35
+2
A:
Arrays are pretty flexible in JS, you can do:
var myArray = new Array();
myArray.push("string 1");
myArray.push("string 2");
JonoW
2009-11-17 13:16:38
+2
A:
With javascript all arrays are flexible. You can simply do something like the following:
var myArray = [];
myArray.push(object);
myArray.push(anotherObject);
// ...
JasonWyatt
2009-11-17 13:17:21