JavaScript - Array shift() Method

Description

Javascript array shift()method removes the first element from an array and returns that element.

Syntax

Its syntax is as follows −

array.shift();

Return Value

Returns the removed single value of the array.

Example

Try the following example.

<html>
   <head>
      <title>JavaScript Array shift Method</title>
   </head>
   
   <body>
   
      <script type="text/javascript">
         var element = [105, 1, 2, 3].shift();
         document.write("Removed element is : " + element ); 
      </script>
      
   </body>
</html>

Output

Removed element is : 105