JavaScript Remove First Element of Array

To remove first element of an array in JavaScript, call shift() method on this array. shift() method modifies the original array, and returns the removed element.

The syntax to remove the first element of array arr is

arr.shift()

Example

In the following example, we have taken an array in arr. We remove the first element from this array using shift() method.

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
</head>
<body>
    <div id="output"></div>
    <script>
        var arr = ['apple', 'banana', 'cherry'];
        arr.shift();
        document.getElementById('output').innerHTML = 'Array : ' + arr;
    </script>
</body>
</html>

Conclusion

In this JavaScript Tutorial, we learned how to remove the first element of an array using shift() method.