I have a several arrays that I need to concat into a new one. I’m doing this:
function ConcatArrays() {
var TheNewArray = [];
function TheConcat(TheArray) { TheNewArray = TheNewArray.concat(TheArray); }
for (var i = 0; i < SomeArrayOfObjects.length; i++) {
if (SomeCondition) { TheConcat(SomeArrayOfObjects[i]); }
}
}
For some reason, TheNewArray is always empty. Is there something I’m missing?
You’re assigning a new array to the local parameter.
This does not affect that variable that you passed as a parameter.
You can add an array to an existing array instance (as opposed to creating a new array) like this: