How to use Array.from() Method In Javascript
The Array.from() method creates a new array instance from an array-like or iterable object. We can use it to create a new array starting from the second element of the original array, effectively excluding the first element.
Example: In this example, we will be using the Array.from() method to find all elements in an array except for the first element.
// Function which takes an array as argument
const print = (arr) => {
return Array.from(arr).slice(1);
}
// Input array
const arr = [10, 20, 30, 40, 50];
// Printing the result
console.log(print(arr));
Output
[ 20, 30, 40, 50 ]
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