how to remove item from an array code example
Example 1: remove a particular element from array
var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");
colors.splice(carIndex, 1);
Example 2: remove item from array javascript
const array = [2, 5, 9];
console.log(array);
const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
}
console.log(array);
Example 3: javascript remove element from array
var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");
colors.splice(carIndex, 1);
Example 4: remove element from array javascript
let values = [1,2,3,4,5,7,8,9,10]
values.length = 5
Example 5: how to remove an element from an array javascript
let myArray = [3, 1, 4, 1, 5, 2];
let unwantedElementIndex = 3;
myArray.splice(unwantedElementIndex, 1);
let myArray = ["[email protected]", "wrong@[email protected]", "..."];
const emailRegexp = ____;
let allCorrectEmails = myArray.filter(element => emailRegexp.test(element));