|
-
Feb 10th, 2004, 10:20 AM
#1
Thread Starter
Hyperactive Member
JavaScript Arrays...Dynamic or Static size
Is there something equivalent to redim? Or does javascript support Arraylists or Vectors?
-
Feb 10th, 2004, 01:04 PM
#2
They're always dynamic 
Code:
var myArray = new Array("abc", "xyz");
myArray[myArray.length] = "ghi";
alert(myArray[2]);
-
Feb 10th, 2004, 06:46 PM
#3
Thread Starter
Hyperactive Member
Maybe you misunderstood (or maybe not).
In vb you can
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.
Any one else feel free to comment please.
Thanks.
-
Feb 11th, 2004, 07:43 AM
#4
Addicted Member
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
Travis, Kung Foo Journeyman
Web Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.5 Guide and Reference
Perl: Documentation, Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
OSS: Mozilla, MySQL (Manual)
-
Feb 11th, 2004, 07:55 AM
#5
Thread Starter
Hyperactive Member
Great, your guys are just full of useful info.
thx again.
sneed
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|