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 Heading Text using JavaScript Current Date in mm/dd/yyyy Format JavaScript Current Date in dd/mm/yyyy Format in JavaScript JavaScript Current Date in yyyy-mm-dd Format JavaScript Get Date Difference in Hours JavaScript Get Date Difference in Minutes JavaScript Get Date Difference in Seconds Get Last Character of String with JavaScript Trigger Button Click On Page Load JavaScript Get id Of Child Element JavaScript Get Id Of Parent Element in JavaScript Get Table Row Index onclick in JavaScript Remove specific option from Select Tag with JavaScript Change Selected Option of Select Tag with JavaScript Get Length of Text In Textarea with JavaScript Change Text Color of Select Tag Option using JavaScript Change Heading Text in JavaScript Get Input Value Length in JavaScript Toggle Button Text with JavaScript Change Background Color of Dropdown with Dropdown using JavaScript Emoji Mood Slider with HTML CSS and JavaScript Hide and Show Div with Radio Button using JavaScript Count Options In Select Tag with JavaScript Get Select Tag Text OnChange with JavaScript Change Background Color OnClick using Input Field