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

Leave a Reply

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

You May Also Like
XOR in Python

XOR in Python

XOR Operator in Python is also known as “exclusive or”  that compares two binary numbers bitwise if two bits are…
How To

How to configure Git proxy?

If you are working in the corporate company all the internet requests usually goes through the corporate firewall.…