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

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *