JavaScript push() | Add New Element at the End of an Array

The JavaScript push() method is used to add a new element at the end of an array. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

   <p id="xyz"></p>

   <script>
      const cities = ["Tokyo", "Bangkok", "Dubai", "Berlin"];
      cities.push("Frankfurt");
      document.getElementById("xyz").innerHTML = cities;
   </script>
   
</body>
</html>
Output

JavaScript push() Syntax

The syntax of push() method in JavaScript is:

array.push(elementOne, elementTwo, elementThree, ..., elementN)

Minimum one element is required.

JavaScript Online Test


« Previous Tutorial Next Tutorial »