JavaScriptNo Comments

default thumbnail
Push() method is used to add item in an array. Multiple items can be added to an array using push() method in javascript.

Javascript


var arr = ["Ajay","Rahul","Deepak"];

// append new value to the array
arr.push("Kapil");
console.log(arr);

Result will be ‘ajay, rahul, deepak, kapil’. Kapil is added to an array using push() method in javascript.

Add Multiple items to an array using javascript

var arr = ["Ajay","Rahul","Deepak"];
arr.push("Pankaj", "Kapil");

for (var i = 0; i < arr.length; i++) {
  console.log(arr[i]);
}

Now pankaj and kapil are added in an array.

Be the first to post a comment.

Add a comment