Friday, May 18, 2018

You don't have to push one thing at a time to an array in JavaScript.

Here is an example of pushing in three objects at once which is perfectly legit.

var foo = [];
var bar = {
   yin: 13,
   yang: 23
};
var baz = {
   yin: 27,
   yang: 42
};
var qux = {
   yin: 69,
   yang: 86
};
foo.push(bar, baz, qux);
console.log(foo);

No comments:

Post a Comment