Explain what is pop() method in JavaScript?
The pop() method is similar as the shift() method but the difference is that the Shift method works at the start of the array. Also the pop() method take the last element off of the given array and returns it. The array on which is called is then altered.
Example
var fruits = [“Banana”, “Orange”, “Lemon”, “Apple”, “Mango”];
fruits.pop();
console.log(fruits);
Output: Array [ “Banana”, “Orange”, “Lemon”, “Apple” ]
What is the use of Push(param) method in JavaScript?
The push method is used to add or append one or more elements to the end of an Array. Using this method, we can append multiple elements by passing multiple arguments.
var fruits = [“Banana”, “Orange”, “Lemon”, “Apple”, “Mango”];
fruits.push(“Cucumber”);
console.log(fruits);
Output: Array [ “Banana”, “Orange”, “Lemon”, “Apple”, “Mango”, “Cucumber” ]
What is unshift method in JavaScript?
Unshift method is like push method which works at the beginning of the array. This method is used interview questions for ui designer to prepend one or more elements to the beginning of the array.
var fruits = [“Banana”, “Orange”, “Lemon”, “Apple”, “Mango”];
fruits.unshift(“Cucumber”);
console.log(fruits);
Output: Array [ “Cucumber”, “Banana”, “Orange”, “Lemon”, “Apple”, “Mango” ]
What is shift method in JavaScript?
var fruits = [“Banana”, “Orange”, “Lemon”, “Apple”, “Mango”];
fruits.shift();
console.log(fruits);
Output: Array [ “Orange”, “Lemon”, “Apple”, “Mango” ]