Hi Friends 👋,

Welcome To Infinitbility! ❤️

This tutorial will help you to add an array of objects to another array in javascript, here we will use the push() method to insert the new array in the array.

JavaScript provides the push() method to add new elements to an existing array, we have to just pass the array in the push() method.

The push() method adds new elements at the last index of the array.

Let’s get started with today’s tutorial How to push an array of objects in another array in javascript?

Before going to an example, let’s see what we are going to do in code…

  1. Create sample array variable
  2. Use the push() method to add a new array of objects
  3. console array to verify whether added or not.

So simple, correct?

// create sampe of array object variable
const sampleArray = [];
console.log("old sampleArray", sampleArray)

// add new array of object in a sampleArray
sampleArray.push([{ userId: 2, name: "aGuideHub", domain: "aguidehub.com" }])
console.log("new sampleArray", sampleArray)

Well, when you run the above code, you can able to see a new array of objects added to the first array.

For now, let’s check the output.

Output

javascript, add array of objects in another array
javascript, add array of objects in another array

All the best 👍.