Shift() vs pop() Method in JavaScript Last Updated : 10 Jan, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report JavaScript shift() and pop() methods are used to remove an element from an array. But there is a little difference between them. The shift() method removes the first element and whereas the pop() method removes the last element from an array. Javascript Array shift() method: The JavaScript Array shift() Method removes the first element of the array thus reducing the size of the original array by 1. Syntax: arr.shift() Example: Below is an example of the array shift() method. JavaScript <script> function func() { // Original array var array = ["GFG", "Geeks", "for", "Geeks"]; // Checking for condition in array var value = array.shift(); console.log(value); console.log(array); } func(); </script> Output: GFG Geeks, for, Geeks Javascript Array pop() method: The JavaScript Array pop() Method is used to remove the last element of the array and also returns the removed element. This function decreases the length of the array. Syntax: arr.pop() Example: Below is the example of the array pop() method. JavaScript <script> function func() { var arr = ['GFG', 'gfg', 'g4g', 'GeeksforGeeks']; // Popping the last element from the array console.log(arr.pop()); } func(); </script> Output: GeeksforGeeks Difference Table: Javascript Array shift() methodJavascript Array pop() methodThis method removes the first element from the array.This method removes the last element from the array.This method shifts the indexes of the elements by -1.This method removes the last index of the array. Comment More infoAdvertise with us Next Article JavaScript Array unshift() Method M manaschhabra2 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Methods Similar Reads JavaScript Array unshift() Method JavaScript Array unshift() Method is used to add one or more elements to the beginning of the given array. This function increases the length of the existing array by the number of elements added to the array.Syntax:array.unshift(element1, element2, ..., elementX);Parameters:element: This parameter 3 min read How to use push() & pop() Methods in JavaScript Arrays? Arrays are dynamic data structures in JavaScript that have the ability to hold several values of various types. The push() and pop() methods are used for adding and removing elements from an array's last index.1. Using push() Method in JavaScriptThe push() method is used to add or push the new value 2 min read JavaScript Array pop() Method The pop() method removes (pops) the last element of an array. The pop() method changes the original array. It reduces the array's length by one and returns the removed element. Syntax:arr.pop();This method does not accept any parameter.Return value:This method returns the removed element array. If t 2 min read JavaScript Array push() Method The push() method in JavaScript adds one or more elements to the end of an array and returns the new length of the array. It modifies the original array, increasing its length by the number of elements added.Syntaxarr.push(element0, element1, ⦠, elementN);ParametersThis method contains as many numb 3 min read JavaScript Map set() Method The JavaScript map.set() method is used to add key-value pairs to a Map object. It can also be used to update the value of an existing key. Each value must have a unique key so that they get mapped correctly.Syntax:GFGmap.set(key, value);Parameters:This method accepts two parameters as mentioned abo 2 min read Alternatives of push() method in JavaScript The task is to perform a push operation without using the push() method with the help of JavaScript. There are two approaches that are discussed below. Approach 1: Use the length property to insert the element at the end of the array. Example: This example implements the above approach. html <bod 2 min read Like