Fill an array with objects from other arrays

I have three arrays:

var arrayOne=[{obj1}, {obj2}, {ob3}];
var arrayTwo=[{obj4}, {obj5}, {obj6}];
var arrayThree=[{obj7}, {obj8}, {obj9}];

And I need to know how to populate a new array with values ​​from these arrays, for example:

var arrayFINAL=[{obj1}, {obj2}, {ob3}, {obj7}, {obj8}, {obj9}, {obj4}, {obj5}, {obj6}];

I thought it was something like this:

var arrayFINAL = new Array(arrayOne, arrayTwo, arrayThree);

But an array of arrays of arrays is created, not an array of objects. Does anyone know how to do this? Thnks!

+3
source share
5 answers
var combinedArray = arrayOne.concat(arrayTwo, arrayThree);

MDN

Syntax
array.concat (value1, value2, ..., valueN)

Live demo

+3
source

You are looking for array concatenation

arrayFinal = arrayOne.concat(arrayTwo, arrayThree);

See here for documentation.

0
source
var arrayFinal = arrayOne.concat(arrayThree,arrayTwo);
0

...

var arrayFINAL = new Array(arrayOne, arrayTwo, arrayThree);

arrayFINAL , , .

, concat()...

var arrayFinal = arrayOne.concat(arrayTwo, arrayThree);

jsFiddle.

, ...

arrayOne.push.apply(arrayOne, arrayTwo.concat(arrayThree));

jsFiddle.

0

You might be interested array_mergein PHJS - the behavior you are looking for is identical to what PHP does array_mergeand the version of PHPJS does the same in JavaScript.

-1
source

All Articles