This article will show you how to remove element(s) from an array in JavaScript, which is probably one of the most commonly used operations in practice when working with JavaScript. Let’s jump right in.
How to remove element(s) from an array in JavaScript
We have many ways to remove element(s) from an array in JavaScript but I will teach you the easiest way. So, please read this article to the end to find out.
Using pop() or shift() method
If you want to remove the last element of an array, you can use the pop()
method. This function returns the last element and removes the last element in the array. Besides that, you can also use the shift()
method to remove the first element of an array.
Syntax:
Remove last element:
pop()
Remove first element:
shift()
Parameters: No parameter.
Return value: The last or the first element removed of the array.
Example:
// Initialize an array var arr1 = ["Learn", "Share", "IT"]; // Remove last element arr1.pop(); // Show array has been deleted the last element console.log("New array after removed the last element:", arr1); // Initialize another array var arr2 = ["5", "12", "532"]; // Remove fisrt element arr2.shift(); // Show array has been deleted the first element console.log("New array after remove the first element:", arr2);
Output:
New array after remove the last element: ["Learn", "Share"]
New array after remove the first element: ["12", "532"]
Using splice() method
You also can remove elements at any position from an array by using the splice()
method. This method removes the element at the specific position and the number of elements you want to remove.
Syntax:
splice(index, number)
Parameters:
- index: The position to begin you want to remove.
- number: The number of elements you want to remove.
Return value: The array removed elements.
Example:
// Initialize an array var arr = ["Learn", "Share", "IT"]; // Get the element at position 1 and remove that element in 'arr' array arr.splice(1, 1); // Show array has been deleted element console.log("New array:", arr);
Output:
New array: ["Learn", "IT"]
Using delete() method
You can remove it at any position with the delete()
method.
Syntax:
delete array[pos]
Parameters:
- pos: The position needs to be removed.
Return value: A new array without element at the pos position.
Example:
// Initialize an array var arr = ["Learn", "Share", "IT"]; // Remove element at the position 1 delete arr[1]; // Show array has been deleted element console.log("New array:", arr);
Output:
New array: ["Learn", null, "IT"]
Using filter() method
This method does not remove elements from our old array. It creates a new array that stores all elements except the value you want to remove from the old array.
Syntax:
filter(bool)
Parameters:
- bool: A function to execute per element in array, it returns the comparison with the true or false condition.
Return value: A new array removed element(s).
Code example:
// Function check positive numbers function checkPositiveNumbers(value) { return value > 0; } // Initialize array var arr = [13, 8, 15, -10, 31, 44, -55]; // Function to filter positive numbers in array "arr" function filterPositiveNumbers() { console.log("New array is:", arr.filter(checkPositiveNumbers)); } filterPositiveNumbers();
Output:
New array is: [13, 8, 15, 31, 44]
Summary
Those are all methods to remove element(s) from an array in JavaScript. I hope it’s helpful for you. If you have any problems or questions, please comment below. I will answer as possible. Thanks for reading!
Maybe you are interested:
- How To Remove The First Element From An Array Using JavaScript
- Remove object from an array by its value in javascript
- Remove the first N elements from an Array using JavaScript

Hi, guys! My name’s Scott Miller. My current job is a software developer and I have shared a lot of quality articles about Javascript, C, C++, C#, Python, PHP, R, Java programming languages. I’m hoping they can assist you.
Name of the university: HCMUS
Major: IT
Programming Languages: C, C++, Python, R, Java, JavaScript