DEV Community

loading...
Cover image for push() Array Method | JavaScript Array Method

push() Array Method | JavaScript Array Method

somanathgoudar profile image Somanath Goudar ・1 min read

You can Prefer to Read or you can Watch on YouTube:

=> The push() method adds a new element to an array (at the end)
=> The push() method returns the new array length

Example:

// Consider an array of Fruits
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");   //  Adds a new element ("Kiwi") to fruits
Enter fullscreen mode Exit fullscreen mode

Example:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
var x = fruits.push("Kiwi");   //  the value of x is 5
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

pic
Editor guide