What is the difference between unshift() and Push() method in JavaScript? Last Updated : 10 Jan, 2023 Comments Improve Suggest changes Like Article Like Report JavaScript Unshift() method is very much similar to the push() method but the difference is that the unshift() method adds the elements at the very beginning of the array whereas the push() method adds at the end of the array. Javascript Array unshift() method: The 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) Example: Below is the example of the Array unshift() method. JavaScript <script> function func() { // Original array var array = ["GFG", "Geeks", "for", "Geeks"]; // Checking for condition in array var value = array.unshift("GeeksforGeeks"); console.log(value); console.log(array); } func(); </script> Output: GeeksforGeeks,GFG,Geeks,for,Geeks. Javascript Array push() method: The JavaScript Array push() Method is used to add one or more values to the end of the array. This method changes the length of the array by the number of elements added to the array. Syntax: arr.push(element1, elements2 ....., elementN]]) Example: Below is the example of the Array push() method. JavaScript <script> function func() { var arr = ['GFG', 'gfg', 'g4g']; // Pushing the element into the array arr.push('GeeksforGeeks'); console.log(arr); } func(); </script> Output: GFG,gfg,g4g,GeeksforGeeks Difference Table: Javascript Array unshift() methodJavascript Array push() methodThis method adds an elements to the beginning of the array.This method adds elements to the end of the array.This method shifts the index of the first element by 1.This method adds a new index at the last of the array. Comment More infoAdvertise with us Next Article What is the difference between unshift() and Push() method in JavaScript? M manaschhabra2 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Methods JavaScript-Questions Similar Reads What is the difference between Map and WeakMap in JavaScript ? In this article, we will talk about the difference between Map and WeakMap which are introduced by ES6. Javascript object supports only one key object. For supporting multiple key objects, Then Map comes on this path. Map: A Map is an unordered list of key-value pairs where the key and the value can 4 min read What is the difference between call and apply in JavaScript ? JavaScript call() Method: It calls the method, taking the owner object as an argument. The keyword this refers to the 'owner' of the function or the object it belongs to. We can call a method that can be used on different objects. Syntax: object.objectMethod.call( objectInstance, arguments ) JavaScr 2 min read What is the difference between Array.slice() and Array.splice() in JavaScript ? In JavaScript, slice() and splice() are array methods with distinct purposes. `slice()` creates a new array containing selected elements from the original, while `splice()` modifies the original array by adding, removing, or replacing elements. slice():The slice() method in JavaScript extracts a sec 3 min read What is the difference between position() and offset() in jQuery ? Both the jQueryUI method the returns the object which contains integer co-ordinate properties of the top and left positions. The positions of top and left coordinates are returned in pixels. Both functions are applied only on visible elements, not on hidden elements. Example: The example gives top a 2 min read What's the difference between toArray and makeArray in jQuery ? In this article, we will learn the difference between the toArray() and makeArray() methods in jQuery. JavaScript toArray() method: This method is used on DOM (Document Object Model) elements to convert them into a JavaScript array. We can iterate this array, calculate its length, and access the ele 3 min read Difference between forEach() and map() loop in JavaScript The forEach() and map() methods in JavaScript are used to iterate over arrays, but they serve different purposes. forEach() executes a provided function once for each array element without returning a new array, while map() transforms elements and returns a new array.JavaScript forEach() JavaScript' 4 min read Difference Between Object.assign and Spread Operator in JavaScript The Object.assign() and the Spread Operator (...) are commonly used for copying properties from one object to another. While they can achieve similar outcomes, they have distinct characteristics and use cases. This article will explain the differences between the Object.assign() and the spread opera 3 min read Delete the first element of array without using shift() method in JavaScript Given an array containing some array elements and the task is to remove the first element from the array and thus reduce the size by 1. We are going to perform shift() method operation without actually using it with the help of JavaScript. There are two approaches that are discussed below: Table of 2 min read Difference Between Array.from and Array.of in JavaScript JavaScript provides various methods for creating and manipulating arrays, two of which are Array.from and Array.of. These methods are part of the ECMAScript 6 (ES6) specification and offer distinct ways to create arrays. Understanding the differences between these two methods is important for effici 3 min read Difference Between Array.prototype.map() and Array.prototype.flatMap() in JavaScript In JavaScript, Array.prototype.map() and Array.prototype.flatMap() are both the methods used to the transform elements in arrays but they differ in their behaviors regarding handling and flattening of the nested arrays.What is Array.prototype.map()?The map() method creates a new array populated with 3 min read Like