Expert Developer JavaScript Question: Download Expert JavaScript Developer PDF

What is Push() method in JavaScript?

Tweet Share WhatsApp

Answer:

► The push() method is used to append one or more elements to the end of an array.
► For example :
var fruits = [ "apple" ];
fruits.push( "banana" );
fruits.push( "mango", "strawberry" );
console.log(fruits);
► We get the following console output :
["apple ", "banana ", "mango ", "strawberry "]
► Using Push() method we can also append multiple elements by passing multiple arguments.
► The elements will be appended in the order of they are inserted i.e. left to right.

Download Expert JavaScript Developer PDF Read All 150 Expert JavaScript Developer Questions
Previous QuestionNext Question
What value does prompt() return if the user clicked the Cancel button?What does a timer do and how would you implement one?