Arrays have been a very useful data type in all the programming languages. They are usually used to describe a collection of elements, values or variables. A lot of us might have come across scenarios where we had to insert a new value into the javascript array. Let us take a look at how to append or add new values to an existing Array using  JavaScript.

Add new values to Array using Array.push()

You can add values to an existing array using Array.push() method available in JavaScript. The Array.push() method accepts comma separated values as parameters and appends the new values to the end of the Array.

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 :

Let’s take a look at another example:

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.

Related Posts

  • How to join or merge an Array in JavaScript? I'm sure you must have had a scenario where you had to join or merge two different Arrays. Well, let me tell you that its an easy task. JavaScript has a native method […]
  • How to empty an array in JavaScript ? Arrays are widely and commonly used in JavaScript. Especially if you are developing a dynamic app, there are very high chances that you might use Arrays in JavaScript. […]
  • How to set a timer in JavaScript? Quite often you might come across scenarios wherein you would need to have a timer set in JavaScript. For instance, you might want to call a function after a delay of […]
  • How to search for a string in JavaScript? The String data type must be the most common data type that we use in JavaScript. One of the most common functionality around string that we would have come across is […]
  • Crossroads.js tutorial with examples Are you making a Single Page Application  or an SPA ? And Do you want to update the url of the page without reloading the page? Do you want your page to respond to the […]
  • How to replace all occurrences of a string in JavaScript? Out of the different "Data Types" in JavaScript, String has been one of my favorites. It is also one of the most widely used Data Type. It would not be an […]