Add new values to Array using Array.push()
The Array.push() method alters an Array by appending the value to it and returns the new length of the Array.
The syntax of Array.push() method is :
arr_name.push(value1, value2, value3, ... , valueN); //where the "arr_name" is an existing array's name.
Let’s take a look at another example:
var colors = ["red", "green"]; var totalColors = colors.push("blue", "yellow"); console.log(colors); // ["red", "green", "blue", "yellow"] console.log(totalColors); // 4
Please note that the array.push() method appends the values to the end of the array. If you would like to insert the values at the beginning of the array then please use array.unshift();
Hope you are clear about the usage of Array.push() method. Do let us know about your queries and also do not forget to Like and Share this page.