how to remove an array object in js code example

Example 1: remove object in array javascript

//1
someArray.shift(); // first element removed
//2
someArray = someArray.slice(1); // first element removed
//3
someArray.splice(0, 1); // first element removed
//4
someArray.pop(); // last element removed
//5
someArray = someArray.slice(0, a.length - 1); // last element removed
//6
someArray.length = someArray.length - 1; // last element removed

Example 2: how to remove an element from an array javascript

let myArray = [3, 1, 4, 1, 5, 2];
let unwantedElementIndex = 3;

// This line removes 1 element from the array, starting at the unwantedElementIndex
myArray.splice(unwantedElementIndex, 1);

// If you have your custom test to remove an element just go for 
// Higher-Order functions
let myArray = ["[email protected]", "wrong@[email protected]", "..."];
const emailRegexp = ____;
let allCorrectEmails = myArray.filter(element => emailRegexp.test(element));