JavaScript Array push() Method

 JavaScript Array push() Method

--------------------------------------------------

Definition and Usage

The push() method adds new items to the end of an array.

The push() method changes the length of the array.

The push() method returns the new length


Syntax 

array.push(item1item2, ..., itemX)


<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h1>JavaScript Array push() Method</h1>
  <script>
    const fruits = ["Banana", "Orange", "Apple", "Mango"];
   
    // console.log(fruits.push("Pine Apple"));
    // console.log(fruits);

    console.log(fruits.push("Pine Apple", "Gauva", "WaterMelon"));
      console.log(fruits);
  </script>

</body>

</html>

Comments

Popular posts from this blog

Javascript Array Concat and Join Method

JavaScript While Loop

JavaScript pop() Method