How to use shift() Method In Javascript
The JavaScript Array shift() Method removes the first element of the array thus reducing the size of the original array by 1.
Example: In this example, we are using shift() Method.
function func() {
// Original array
let array = [34, 234, 567, 4];
// Checking for condition in array
let value = array.shift();
console.log(array);
}
func();
Output
[ 234, 567, 4 ]
How to get all Elements Except First in JavaScript Array?
We will find all the elements in a given array except for the first one using JavaScript. We have a few methods to do this in JavaScript that are described below:
Table of Content
- Using for loop
- Using slice() Method
- Using Array.filter method
- JavaScript Array.reduce() Method
- Using shift() Method
- Using Array.from() Method
Contact Us