Monday, 31 August 2015

javascript array add multiple items into array

multiple items into array

1,

array.push(item1item2, ..., itemX)

2.

array.push([a,b,c])

3. contact

method 2 is not reliable sometime.
method 3 will return a new array without changing the original one.

So i suggest to do this:

for (var i = sourceArray.length - 1; i >= 0; i--) {
            targetArray.push(sourceArray[i]);
};

Clear and safe.

No comments:

Post a comment