How do I remove a particular element from an array in JavaScript?

remove a particular element from an array in JavaScript

There are different methods and techniques you can use to remove elements from JavaScript arrays.

  • pop – Removes from the End of an Array
  • shift – Removes from the beginning of an Array
  • splice – removes from a specific Array index



Pop

var array = [1, 2, 3, 4, 5, 6];
array.pop();

OutPut
// [1, 2, 3, 4, 5]



shift

var array = [1, 2, 3, 4, 5, 6];
array.shift();

OutPut
// [2, 3, 4, 5, 6]



splice

var arr = [1, 2, 3, 4, 5, 6];
var removed = arr.splice(0,2);

OutPut
// [3, 4, 5, 6]




All Comments

Leave a Reply

Your email address will not be published. Required fields are marked *