javascript push object to array code example
Example 1: js array add element
array.push(element)
Example 2: javascript pushing to an array
some_array = ["John", "Sally"];
some_array.push("Mike");
console.log(some_array);
["John", "Sally", "Mike"]
Example 3: js add item to array
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
Example 4: js push array
var array = [];
var element = "anything you want in the array";
array.push(element);
Example 5: how to add objects in array
var a=[], b={};
a.push(b);
Example 6: js push in object
let obj = {};
let objToAdd1 = { prop1: "1", prop2: "2" };
let objToAdd2 = { prop3: "3", prop4: "4" };
obj = { ...obj, ...objToAdd1 };
obj = { ...obj, ...objToAdd2 };
console.log(obj);