How to remove element from array in JavaScript

To remove an element from array:

1. Get element index with indexOf() method.

2. Use a splice() method on the specific array with your index as the parameter.

<script>
    array.splice(array.indexOf('elementToDelete'));
</script>

Example:

<script>
    var array = ['element1', 'cat', 'element2', 'element3'];

    console.log(array);

    var index = array.indexOf('cat');
    array.splice(index, 1);

    console.log(array);
</script>

Output (console):

(4) ['element1', 'cat', 'element2', 'element3']
(3) ['element1', 'element2', 'element3']