JavaScript - Delete Elements from the End of a JS Array Last Updated : 14 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report These are the following ways to delete elements from the end of JavaScript arrays:1. Using pop() methodThe pop() method is used to remove the last element from an array and returns the modified array. JavaScript let a = [1, 2, 3, 4]; // Remove last element a.pop(); console.log(a); Output[ 1, 2, 3 ] 2. Using splice() methodThe splice() method can remove elements from any index of the array, including the end. JavaScript let a = [1, 2, 3, 4]; // Remove last element a.splice(a.length - 1, 1); console.log(a); Output[ 1, 2, 3 ] 3. Using Destructuring AssignmentArray destructuring is used to extract the elements of the array except the last one and create a new array. JavaScript let a1 = [1, 2, 3, 4]; // Remove last element const [ ...a2 ] = a1; a2.length = a1.length - 1; console.log(a2); Output[ 1, 2, 3 ] 4. Using slice() MethodThe slice() method is used to remove the last element by specifying the end index. The slice() method creates a new array. JavaScript let a1 = [1, 2, 3, 4]; let a2 = a1.slice(0, -1); console.log(a2); Output[ 1, 2, 3 ] 5. Using length propertyThe JS length property is used to remove the last element of the array by setting the array.length to array.length - 1. JavaScript let a = [1, 2, 3, 4]; a.length = a.length - 1; console.log(a); Output[ 1, 2, 3 ] 6. Using Custom Loop The JS for loop is used to iterate from the first element to the second last element of the array copying the elements to the new array. JavaScript let a1 = [1, 2, 3, 4]; // Create a new array and copy elements except the last one let a2 = []; for (let i = 0; i < a1.length - 1; i++) { a2.push(a1[i]); } console.log(a2); Output[ 1, 2, 3 ] Comment More infoAdvertise with us Next Article JavaScript - Delete Elements from the End of a JS Array A amit_singh27 Follow Improve Article Tags : JavaScript Web Technologies javascript-array Similar Reads JavaScript - Delete Element from the Beginning of JS Array These are the following ways to delete elements from JavaScript arrays:1. Using shift() method - Mostly UsedThe shift() method removes the first element from the array and adjusts its length.JavaScriptconst a = [1, 2, 3, 4]; // Remove the first element a.shift(); console.log(a);Output[ 2, 3, 4 ] 2. 2 min read JavaScript - Delete Elements from an Index in JS Array These are the following ways to delete elements from a specified Index of JavaScript arrays:1. Using splice() MethodThe splice() method is used to remove elements directly from a specified index in an array by specifying the index and the number of elements to delete.JavaScriptlet a = [1, 2, 3, 4, 5 1 min read JavaScript - Remove n Elements From End Array Here are the different methods to remove n elements from the end of a given array in JavaScript1. Using splice() Methodsplice() method is used to modify an array by adding or removing elements from it. It accepts the index from which the modification has to be made and the number of elements to dele 3 min read How to delete an element from an array using JavaScript ? The array is a type of data structure that allows us to store similar types of data under a single variable. The array is helpful to create a list of elements of similar types, which can be accessed using their index. In this article, we will discuss different ways to remove elements from the array. 5 min read JavaScript - Delete First Occurence of Given Element from a JS Array These are the following ways to delete elements from a specified Index of JavaScript arrays:1. Using indexOf() and splice() - Most UsedThe indexOf() method finds the first occurrence of the element in the array, and splice() removes it at that index. This approach directly modifies the original arra 2 min read Like