Navigate back to the homepage

How to add array to another array in javascript?

Infinitbility
JavaScript
May 3rd, 2022 · 1 min read
keep affilitate

Hi Friends 👋,

Welcome To Infinitbility! ❤️

This tutorial will help you to add an array 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 add an array to 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
  3. console array to verify whether added or not.

So simple, correct?

1// create sampe of array object variable
2const sampleArray = [
3 [{ userId: 1, name: "infinitbility", domain: "infinitbility.com" }],
4];
5console.log("old sampleArray", sampleArray)
6
7// add new object in a sampleArray
8sampleArray.push([{ userId: 2, name: "aGuideHub", domain: "aguidehub.com" }])
9console.log("new sampleArray", sampleArray)

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

For now, let’s check the output.

Output

javascript, add array in another array
javascript, add array in another array

All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

melio affilitate

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

How to convert date to milliseconds in typescript?

TypeScript, convert date to milliseconds example.

May 2nd, 2022 · 1 min read

How to convert date to iso format in typescript?

TypeScript, convert date to iso string example.

May 1st, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]