How to remove specific elements from the left of a given array of elements using JavaScript ? Last Updated : 27 May, 2024 Comments Improve Suggest changes Like Article Like Report In this article, we will learn How to remove specific elements from the left of a given array of elements using JavaScript. We have given an array of elements, and we have to remove specific elements from the left of a given array. Here are some common approaches: Table of Content Using splice() methodUsing shift MethodApproach: Using splice() methodThe splice() method is used to add and remove elements from an array. To remove specific elements from the left of a given array, we will use the splice method. To remove specific elements it takes two parameters index form where we want to remove the element and the number of the elements we want to remove. It returns an array that contains removed elements. Syntax: array.splice(index,No_of_element);Example: In this example, we will remove specific elements from the left of a given array of elements using JavaScript using the splice() method. JavaScript function fun(n) { // Array var arr = [2, 4, 5, 3, 6]; // Find index of specified element which is n var ind = arr.indexOf(n); // Remove n from array if it exists if (ind !== -1) { arr.splice(ind, 1); } // Log the results to the console console.log("After removing element:"); console.log(arr); } // Call the function with the specified element to remove fun(5); OutputAfter removing element: [ 2, 4, 3, 6 ] Using shift MethodThe shift method removes the first element from an array and returns that element. This method modifies the original array directly, reducing its length by one. It's a simple and effective way to remove an element from the start of an array. Example: In this example we removes the first element from array using shift(), which modifies the array and returns the removed element. It then logs the updated array and the removedElement to the console. JavaScript let array = [1, 2, 3, 4, 5]; let removedElement = array.shift(); console.log(array); console.log(removedElement); // 1 Output[ 2, 3, 4, 5 ] 1 Comment More infoAdvertise with us S sachinchhipa44 Follow Improve Article Tags : JavaScript Web Technologies javascript-array JavaScript-DSA JavaScript-Methods JavaScript-Questions +2 More Similar Reads How to Remove First and Last Element from Array using JavaScript? Removing the first and last elements from an array is a common operation. This can be useful in various scenarios, such as data processing, filtering, or manipulation. Example:Input: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]Output: [ 2, 3, 4, 5, 6, 7, 8, 9 ]Removing first and last element in array can be do 2 min read How to move specified number of elements to the end of an array in JavaScript ? The purpose of this article is to move some specified elements to the end of an array using JavaScript.Given an array of length say N, move some specified amount of elements say X to the end of the given array.Input:arr = [1, 2, 3, 4, 5]X = 2Output: The following array should be the output as the fi 3 min read How to remove specific div element by using JavaScript? Removing a specific `<div>` element with JavaScript is crucial for dynamic web content management. Whether updating information, responding to user actions, or optimizing performance by cleaning the DOM, efficient DOM manipulation is essential. JavaScript offers diverse methods such as `remove 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 How to get removed elements of a given array until the passed function returns true in JavaScript ? The arrays in JavaScript have many methods which make many operations easy. In this article let us see different ways how to get the removed elements before the passed function returns something. Let us take a sorted array and the task is to remove all the elements less than the limiter value passed 4 min read Like