JavaScript Program to Append an Object to An Array Using push() Method Full Project For Beginners

 

 

script.js

 

 

// program to append an object to an array

function insertObject(arr, obj) {

    // append object
    arr.push(obj);
    
    console.log(arr);
}

// original array
let array = [1, 2, 3];

// object to add
let object = {x: 12, y: 8};

// call the function
insertObject(array, object);

Leave a Reply