Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Remove Duplicate Elements from JavaScript Array
Next article icon

Remove Elements From a JavaScript Array

Last Updated : 16 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Here are the various methods to remove elements from a JavaScript Array

Remove-Array-Elements

Remove elements from Array

1. Using pop() method

The pop() method removes and returns the last element of an array. This function decreases the length of the array by 1 every time the element is removed.

javascript
let a = ["Apple", "Banana", "Orange", "Mango"];  // Removing the last element let pop = a.pop();  console.log("Removed Element: ", pop); console.log("Updated Array: ", a); 

In this Example:

  • The pop() method removes the last element from the array ("Mango" in this case) and returns it, modifying the original array.
  • The pop() method returns the removed element ("Mango") so you can store or use it as needed. The updated array, without the last element, is then printed.

Note : Please Read JavaScript Array Tutorial for complete understanding of JavaScript Array.

2. Using shift() Method

The shift() method is used to remove and return the first element of the array and reduce the size of the original array by 1. 

javascript
let a = ["Apple", "Banana", "Orange", "Mango"];  // Removing the first element let fEle = a.shift();  console.log("Removed Element: ", fEle); console.log("Updated Array: ", a); 

In this Example:

  • splice() can remove existing elements or add new ones at any position within the array.
  • It returns an array containing the elements that were removed, allowing you to keep track of what was deleted.

3. Using splice() Method

The splice() method is used to modify the contents of an array by removing the existing elements and/or adding new elements.

javascript
let a = ["Apple", "Banana", "Orange", "Mango"];  // Removing the specified element let rEle = a.splice(1, 1);  console.log("Removed Element: ", rEle); console.log("Updated Array: ", a); 

In this Example:

  • The splice() method is used here to remove the element at index 1 (which is "Banana") from the array. The first argument (1) specifies the index, and the second argument (1) indicates that one element should be removed.
  • The splice() method returns an array containing the removed element (["Banana"]), which is stored in the rEle variable. The updated array (["Apple", "Orange", "Mango"]) is then printed without the removed element.

4. Using filter() Method

If we need to remove elements based on a condition, the filter() method is best option. It creates a new array with only the elements that meet the condition.

javascript
function isPositive(val) {     return val > 0; }  let a = [10, 25, 30, -10, 32, -35]; let filtered = a.filter(isPositive);  console.log("Positive Array Elements: ", filtered); 

In this Example:

  • The filter() method goes through each number in the array a and uses the isPositive() function to check if the number is greater than 0 (positive).
  • It then creates a new array, filtered, which only includes the numbers that are positive (10, 25, 30, 32) and ignores the negative ones. The result is then shown in the console.

5. Using Delete Operator

The delete operator returns a boolean value true, if the element or property is removed from the array or object and false, if a function or variable is passed to remove.

javascript
let a = ["Apple", "Banana", "Orange", "Mango"];  // Delete Element at Index 2 let deleted = delete a[2];  console.log("Removed Element: ", deleted); console.log("Updated Array: ", a); 

In this Example:

  • The delete operator is used to remove the element at index 2 (which is "Orange") from the array a. However, this method only removes the element, leaving a hole (i.e., the index will be undefined).
  • The delete operator returns true, but the array still keeps the same length, with a hole where “Orange” was.

6. Using Array Reset

Removing the elements from an array using the manual clear and reset approach either by resetting the length of the array as 0 using the length property or by assigning the array to an empty array([]).

javascript
let a1 = ["Apple", "Banana", "Orange", "Mango"]; let a2 = [10, 20, 30, 40, 50];  // After Deleting Each Element of an Array a1 = []; a2.length = 0;  console.log("Updated Array1: ", a1); console.log("Updated Array2: ", a2); 

In this Example:

  • The array a1 is set to an empty array ([]), which completely clears all the elements from it.
  • The length of the array a2 is set to 0, which removes all elements from the array while still keeping the array reference intact.

7. Using for() Loop and New Array

A simple for loop will be run over the array and pushes all elements in the new array except the element that has to be removed.

JavaScript
let rEle = (a, n) => {     let newA = [];      for (let i = 0; i < a.length; i++) {         if (a[i] !== n) {             newA.push(a[i]);         }     }      return newA; };  // Driver Code let a = [10, 20, 30, 40, 50]; let rElement = 20;  let res = rEle(a, rElement);  console.log("Updated Array: ", res); 

In this Example:

  • The function rEle removes a specific element (n) from the array a. It creates a new array (newA) and adds all elements from a except the element n (in this case, 20).
  • After filtering out the specified element, the new array is returned and displayed. The result is logged, showing the updated array without the element 20. The final array is [10, 30, 40, 50].

8. Using lodash _.remove() Method

We can remove the array elements using Lodash library. The lodash _.remove() method is used to remove the element from array. To use the lodash library, you need to install it locally on your system.

JavaScript
// Import Lodash Library const _ = require('lodash');  // Declare and Initialize an Array let a = [101, 98, 12, -1, 848];  // Using _.remove() Method to Remove Odd Number let even= _.remove(a, function(n) {     return n % 2 == 0; });  console.log("Remaining Odd Elements: ", a); console.log("Removed Even Elements: ", even);   

In this Example:

  • _.remove() removes even numbers from the array a and returns them in the even array.
  • The remaining odd numbers are in the modified a, and the removed even numbers are in the even array.

9. Using forEach() and splice() Methods

This method uses forEach to iterate over the array and indexOf to find the index of the element that needs to be removed. The splice method is then used to remove the element at that index.

JavaScript
// Function to remove specific element from a function remEt(a, ele) {     a.forEach((item, index) => {         if (item === ele) {             a.splice(index, 1);         }     });     return a; }  // Declare and Initialize an Array let a = ["Apple", "Banana", "Orange", "Mango"];  // Remove Specific Item from Array remEt(a, "Banana");  console.log("Updated Array: ", a); 

In this Example:

  • The remEt function loops through the array a and removes the specified element ("Banana") using splice() when it matches.
  • The updated array is logged, showing that "Banana" has been removed, and the remaining elements are ["Apple", "Orange", "Mango"].





Next Article
Remove Duplicate Elements from JavaScript Array

S

Sabya_Samadder
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • javascript-array
  • JavaScript-DSA
  • JavaScript-Questions

Similar Reads

  • How to Add Elements to a JavaScript Array?
    Here are different ways to add elements to an array in JavaScript. 1. Using push() MethodThe push() method adds one or more elements to the end of an array and returns the new length of the array. Syntax array.push( element1, element2, . . ., elementN );[GFGTABS] JavaScript const arr = [10, 20, 30,
    3 min read
  • Create an Array of Given Size in JavaScript
    The basic method to create an array is by using the Array constructor. We can initialize an array of certain length just by passing a single integer argument to the JavaScript array constructor. This will create an array of the given size with undefined values. Syntax cosnt arr = new Array( length )
    4 min read
  • Insert at the Beginning of an Array in JavaScript
    Following are different ways to add new elements at the beginning of an array 1. Using the Array unshift() Method - Most Used:Adding new elements at the beginning of the existing array can be done by using the Array unshift() method. This method is similar to the push() method but it adds an element
    2 min read
  • Remove Elements From a JavaScript Array
    Here are the various methods to remove elements from a JavaScript Array 1. Using pop() methodThe pop() method removes and returns the last element of an array. This function decreases the length of the array by 1 every time the element is removed. [GFGTABS] javascript let a = ["Apple",
    6 min read
  • Remove Duplicate Elements from JavaScript Array
    To Remove the elements from an array we can use the JavaScript set method. Removing duplicate elements requires checking if the element is present more than one time in the array. 1. Using JavaScript Set() - Mostly UsedThe JavaScript Set() method creates an object containing only unique values. To r
    3 min read
  • How to Remove Multiple Elements from Array in JavaScript?
    Here are various methods to remove multiple elements from an array in JavaScript 1. Using filter() MethodThe filter() method creates a new array with the elements that pass the condition. This method does not change the original array. [GFGTABS] JavaScript let a = [1, 2, 3, 4, 5]; let remove = [2, 4
    4 min read
  • Insert at the Beginning of an Array in JavaScript
    Following are different ways to add new elements at the beginning of an array 1. Using the Array unshift() Method - Most Used:Adding new elements at the beginning of the existing array can be done by using the Array unshift() method. This method is similar to the push() method but it adds an element
    2 min read
  • Reverse an Array in JavaScript
    Here are the different methods to reverse an array in JavaScript 1. Using the reverse() MethodJavaScript provides a built-in array method called reverse() that reverses the elements of the array in place. This method mutates the original array and returns the reversed array. [GFGTABS] JavaScript let
    3 min read
  • JavaScript - Delete last Occurrence from JS Array
    These are the following ways to remove the last Item from the given array: 1. Using pop() Method (Simple and Easiest Method for Any Array) The pop() method is used to get the last element of the given array it can also be used to remove the last element from the given array. [GFGTABS] JavaScript let
    2 min read
  • Remove Empty Elements from an Array in JavaScript
    Here are different approaches to remove empty elements from an Array in JavaScript. 1. Using array.filter() MethodThe array filter() method is used to create a new array from a given array consisting of elements that satisfy given conditions. array.filter( callback( element, index, arr ), thisValue
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences