Javascript shift() Method - Array Function

How to delete elements from the begining / first element of the array and shift the index of the subsequent elements down ?
What is the use of shift() function in javascript?

Explanation

Method: shift() :
This function delete the first element of the array and shift the index of the subsequent elements to the lower value to occupy the vacant space and returns the deleted element.
Syntax:
array1.shift();

Example:


<script language="javascript">
var a=["H","E","L","L","O"];
var ele = a.shift();
document.write(ele);
</script>

Result:




Ask Questions

Ask Question