Navigate back to the homepage

How to add items to array in javascript?

April 30th, 2022 · 1 min read
keep affilitate

Hi Friends 👋,

Welcome To Infinitbility! ❤️

This tutorial will help you to add new items or elements to your array, here we will use the push() method to insert the new element in the array.

JavaScript provides the push() method to add new elements an existing array, we have to just pass elements 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 items to an 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 push() method to add new element
  3. console array to verify added or not.

So simple, correct?

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

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

For now, let’s check the output.


javascript, add item in a array
javascript, add item in a 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



More articles from Infinitbility

How to convert date to timestamp in typescript?

TypeScript, convert date to timestamp example.

April 29th, 2022 · 1 min read

How to convert date to mm/dd/yyyy in typescript?

TypeScript, convert date to mm/dd/yyyy format example.

April 27th, 2022 · 1 min read
© 2020–2022 Infinitbility
Link to $ to $ to $ to $ to $ to $mailto:[email protected]