Removing an element from an array in JavaScript can mean removing the first item, the last item, a specific index, or every matching value. The right method depends on whether you want to mutate the original array or create a new one.
The most common tools are pop(), shift(), splice(), filter(), and delete. If you need the inverse operation, add arrays in JavaScript is the nearby topic.
Tested on: Node.js v20.18.2. A short note after each runnable snippet describes what you should see in the console.
Method 1: Remove the last element with pop()
pop() removes the last item and changes the original array.
const names = ["Lorem", "Ipsum", "Doe", "Reh"];
names.pop();
console.log("remove-pop:", names.join(","));You should see one line logging remove-pop: Lorem,Ipsum,Doe.
Use this when you want to trim the end of the array.
Method 2: Remove the first element with shift()
shift() removes the first element and returns it.
const names = ["Lorem", "Ipsum", "Doe", "Reh"];
names.shift();
console.log("remove-shift:", names.join(","));You should see one line logging remove-shift: Ipsum,Doe,Reh.
This is the right method when the array behaves like a queue.
Method 3: Remove by index with splice()
splice() removes items from the middle of the array in place.
const words = ["Lorem", "Ipsum", "Doe", "Reh"];
words.splice(2, 1);
console.log("remove-splice:", words.join(","));You should see one line logging remove-splice: Lorem,Ipsum,Reh.
Use this when you know the index and want to mutate the original array.
Method 4: Remove matching values with filter()
filter() returns a new array with the matching item removed.
const arr = ["a", "b", "c", "d"];
const removed = arr.filter((_, index) => index !== 1);
console.log("remove-filter:", removed.join(","));You should see one line logging remove-filter: a,c,d.
This is the best choice when you want an immutable array update.
Method 5: Why delete is not the same as removal
delete leaves an empty slot instead of shrinking the array.
const arr = ["a", "b", "c"];
delete arr[1];
console.log("remove-delete:", arr.length, 1 in arr);You should see one line logging remove-delete: 3 false.
Avoid delete when you want a compact array.
Summary
To remove an element from an array in JavaScript, use pop() for the end, shift() for the start, splice() for a specific index, and filter() when you want a new array. delete does not truly remove the slot, so it is usually not the right tool for array cleanup.

