Answers for "how to remove array element from index in javascript"

49

javascript remove from array by index

//Remove specific value by index
array.splice(index, 1);
Posted by: Guest on May-06-2020
1

javascript remove element from array

const array = [2, 5, 9];

console.log(array);

const index = array.indexOf(5);
if (index > -1) {
  array.splice(index, 1); // 2nd parameter means remove one item only
}

// array = [2, 9]
console.log(array); 
 Run code snippet
Posted by: Guest on January-26-2022

Code answers related to "how to remove array element from index in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language