Append Values into an Array in JavaScript using push() method

Most of the JavaScript developers come across this scenario where they need to insert or append the values into an existing array. You could Append Values into an Array in JavaScript using push() method. Let’s look at JavaScript Array push() Method in details.

What is JavaScript Array push() Method?

The push() method adds one or more elements to the end of an array and returns the new length of the array.

The push method is very generic and we can use this method with call() or apply() on objects resembling arrays. The push method depends on the array length to determine the inserting of new elements. If the array length property cannot be converted to a number then it would start inserting the items from 0 index position. push() also returns the new length of an array.

Syntax of push() Method

arr.push(element1, …, elementN)

Recommended Articles

Append Values into an Array in JavaScript

//Creating new array

var names=['Jack','Mark'];
var arrLength=names.push("Obama","Bill");
console.log(arrLength); //4
console.log(names);//['Jack','Mark','Obama','Bill']
Leave a Reply

Your email address will not be published.

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like
Number.isinteger() - Javascript

Number.isInteger() – JavaScript

Table of Contents Hide SyntaxPassing positive number as an argument Passing negative number as an argument Passing zero as an argument Passing floating-point number as an argument Passing floating-point number as an argument representing…
View Post