... ?
"
, !
function go(val){
numbers[i]=val;
i++;
}
( i - undefined) - ,
numbers.push(val);
and if you need i to equal what will be the index of the next element of the array is undefined, then
i = numbers.length;
To increase the value, you must first have numerical values for some elements of the array; then your function will need an index whose value will increase
var numbers = [0,0,0,0];
function go(i){
numbers[i]++;
}
go(1);
go(3);
go(1);
alert(numbers);
will show 0,2,0,1
But if your goal is to put the value in a new element at the end of the array, just use .push ()
and .length will say how many elements there are; no need to increase i
source
share