How to remove first array element in JavaScript and return it?


To remove first array element, use the JavaScript shift() method. JavaScript array shift() method removes the first element from an array and returns that element.

Example

You can try to run the following code to remove first array element and return it −

Live Demo

<html>
   <head>
      <title>JavaScript Array shift Method</title>
   </head>
   <body>
      <script>
         var element = [30, 45, 70, 90, 110].shift();
         document.write("Removed first element is : " + element );
      </script>
   </body>
</html>

Output

Removed first element is : 30

Updated on: 18-Jun-2020

151 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements