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>

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

      const cities = ["Tokyo", "Bangkok", "Dubai", "Berlin"];
      document.getElementById("xyz").innerHTML = cities;

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 »

Follow/Like Us on Facebook

Subscribe Us on YouTube