Array and auto-increment

Hi,

How would you “auto-increment” an array in javascript?


myArray[] = 'foo';
myArray[] = 'bar';

It should be the same as myArray[0] and myArray[1].

Regards,

-jj. :slight_smile:

May be

https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/push

but I’m not sure what you are looking for.

Yup, use push() or myArray[myArray.length] = ‘foo’;


myArray.push('foo');
myArray.push('bar');

// or

myArray[myArray.length] = 'foo';
myArray[myArray.length] = 'bar';