In this tutorial we will see How To Remove First Element From Array in JavaScript. JavaScript built-in shift() method can be used to remove first element of array.
Table of Contents
JavaScript shift() method
The JavaScript shift() method removes the first element from the array. shift() method also returns the first element of that array.
In this tutorial we can also use shift() method to remove first element of our array.
JavaScript Code
Take a look at the JavaScript code, the shift method will remove the first element of array and it will be stored in the variable x.
.write() method is used to display the array before and after removing the first element.
<script>
var array = [912, 232, 601, 521]; // array
document.write('Array: '+ array);
document.write('<br>');
var x = array.shift(); // removing first element
document.write('Removed Element: '+ x);
document.write('<br>');
document.write('New Array: '+ array);
</script>
Demo
Video Tutorial
Watch video tutorial on How To Remove First Element From Array using JavaScript.