
Originally Posted by
PHPycho
Hello forums !!
I would like to push the values in array(without specifying index).
Can anybody give me the suggestion.
Note: It should be equivalent to PHP's
PHP Code:
$exp_array = array();
$exp_array[] = "value1";
$exp_array[] = "value2";
(without specifying indexes)
...........etc
Thanks in advance to all of you.
I'm not sure why you don't want to specify indices. If you mean that you don't want to have to do:
Code:
var i = 0;
var a = new Array();
a[i] = 'foo';
++i;
a[i] = 'bar';
++i
etc. then this is an idiom I've seen used often:
Code:
var a = new Array();
a[a.length] = 'foo';
a[a.length] = 'bar';
Does that help?
Bookmarks