Remove an item from array JavaScript

Below is an example to remove an item from an array in JavaScript:

const arrayItems = [1, 2, 3];

const index = arrayItems.indexOf(2);
if (index > -1) {
  arrayItems.splice(index, 1);
}
console.log(arrayItems);
// array = [1,3]

The output will be [1,3] as we have removed the item with value “2”.