by Sai gowtham

Removing the particular element from an array in JavaScript

In this tutorial, we are going to learn how to remove the particular element from an array in JavaScript.

Using the splice() method

JavaScript has a built-in thesplice() method by using that we can remove a particular element from an array by passing the element index.

Here is an example, that removes the orange, grapes from the following array.

const arr = ['apple','orange','grapes','jackfruit'];

arr.splice(1,1); // orange is removed

arr.splice(2,1); // grapes is removed.

// after removing items the array look like this

console.log(arr); // ['apple','jackfruit']
  • The first argument in the slice() method is start-index.
  • The second argument in the slice() method is deleteCount, it means the number of elements to remove from the array.

Note: The splice() method modifies the original array.

Learn more about the splice() method.

Top Udemy Courses

JavaScript - The Complete Guide 2021 (Beginner + Advanced)
JavaScript - The Complete Guide 2021 (Beginner + Advanced)
64,026 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
152,857 students enrolled
48.5 hours of video content
View Course