- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 −
<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
Advertisements