I would like to know:
- When do you use the indexing method to assign values to a new array?
- and; When do you use the push method?
I know you can assign a value to an array in a for loop by using indexing.
My question is:
I have a for loop that looks like this:
for (i=array_len-2;i>0;i-=2)
{
var new_arry=array[i]
}
... that would just return the value for i
. It does not store it in the new array.
but, if i do that same thing:
for (i=array_len-2;i>0;i-=2)
{
var new_arry=array.push(i)
}
it adds the new element in the array in the format of [element one , element two].