Remove First Element From Array JavaScript

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.

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.

Get Last Element Of Array Without Removing It Remove Last Element From Array JavaScript Remove First Element From Array in JavaScript Tic Tac Toe Game in JavaScript Remove Class from HTML Tag OnClick JavaScript JavaScript Select li Tag By Index Display JavaScript Variable In HTML Insert HTML Code anywhere With JavaScript JavaScript Date Difference in Days JavaScript Hide Button After Click Simple Click and Hold Effect Using JavaScript Remove Class From All Elements in JavaScript JavaScript Select All HTML Elements Whose ID Start With Same String Count Checked Checkboxes of Specific Form with JavaScript Enable and Disable Button using JavaScript Add Class to HTML Tag On Click using JavaScript Change Class of HTML Tag Using JavaScript Get All Options In Select Tag using JavaScript Replace a Word from everywhere in a String using JavaScript Execute a Function on Hover Using JavaScript