You could use the apply
method and push the entire array at once. Never tried with a matrix like array.
Example:
var tempArray = [], tempArray2 = [];
for(var j = 0, dataLen = data.length; j < dataLen; j++) {
tempArray2.push.apply(tempArray2, data[j]);
tempArray.push(tempArray2), tempArray2 = [];
}
jsFiddle:
http://jsfiddle.net/k264S/6/
Or as pointed by cookie monster using slice()
without a parameter will create a shallow copy (it will not copy the values at references too).
Example:
var tempArray = [];
for(var j = 0, dataLen = data.length; j < dataLen; j++) {
tempArray.push(data[j].slice());
}
This will work as long as your data[j]
has less than ~150.000 elements in it.
If it has more, you should use the technique mentioned in this answer: How to extend an existing JavaScript array with another array, without creating a new array?