Is there something equivalent to redim? Or does javascript support Arraylists or Vectors?
Printable View
Is there something equivalent to redim? Or does javascript support Arraylists or Vectors?
They're always dynamic :)
Code:var myArray = new Array("abc", "xyz");
myArray[myArray.length] = "ghi";
alert(myArray[2]);
Maybe you misunderstood (or maybe not).
In vb you can
Any one else feel free to comment please.VB Code:
dim MyArray() redim MyArray (100) 'do stuff with array. Decide you need a bigger array. redim preserve MyArray (150) 'now the 1st 100 elements still contain that original data, except there are 50 more elements. I am sorry if your example does that. I don't have time to check before leaving work today.
Thanks.
Axion's example does that. JavaScript arrays are always dynamic. The code handles the array's dimensions for you, you never have to worry about it.
Code:var myArray = new Array(); //currently the array is completely empty, it will return no elements, but will support push() and such
myArray[0] = "foo"; //The array now has a length of 1, and the value of the first element is a string
myArray.push("bar"); //The array now has a length of 2
myArray[99] = "blah"; //The array now has a length of 100
//but only the first two and the last one elements have values assigned
//the rest are still empty
Great, your guys are just full of useful info.
thx again.
sneed