Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fill an array with objects from other arrays

Tags:

javascript

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 fill a new array with values from those arrays, like this:

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 it seems to create an array an array's of arrays not an objects array. Anyone knows how to do this? thnks!

like image 200
lilymz Avatar asked May 22 '26 22:05

lilymz


1 Answers

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

MDN

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

Live DEMO

like image 135
gdoron is supporting Monica Avatar answered May 25 '26 11:05

gdoron is supporting Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!