Wednesday, 23 August 2017

javascript - Array.push() doesn't work as expected

I have an array. For test purposes i output its contents like this:



for (var i=0; i        console.log(i + ':' + array1[i]);
}


0:String1
1:String2


Now i have a second array. What i want to do is push the contents of array1, into array2.



I do this with this line:



array2.push(array1);


Unfortunately, the contents aof the first array, exist in only one index of the second array. Separated by commas.



For example, if we use view the contents of the second array after the action it will be something like this:



for (var i=0; i        console.log(i + ':' + array1[i]);
}


0:Old_string1
1:Old_string2
2:Old_string3
3:Old_string4
4:String1,String2


While i would like this outout:



4:String1
5:String2

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...