Like others have said, .concat
returns a new array, and does not mutate the original state of the arrays you are working with. If you want the value of two arrays being joined via .concat
you must store it in a variable or simply do the concatenation it where you need it.
example:
var greetings = [{"affirmative":"yeah"}];
var exclamations = [{"omg":"Oh my golly-gee-wilickers!"},{"wowz":"wowzers!"}];
var obArray = greetings.concat(exclamations);
console.log(obArray); // returns [obj, obj, obj]
This would give you the same result:
console.log(greetings.concat(exclamations));
One last thing. Methods like .concat
are chain-able.