Horje
What is the use of the Array.from() method in JavaScript ?

In JavaScript, the Array.from() method is used to create a new array instance from an iterable object or array-like object. It provides a way to convert objects that are not inherently arrays into actual arrays.

Example: Here we see that output creates a new array whose content is the same as input in the case of an integer.

Javascript

console.log(Array.from("GeeksforGeeks"));
console.log(Array.from([10, 20, 30]));

Output

[
  'G', 'e', 'e', 'k',
  's', 'f', 'o', 'r',
  'G', 'e', 'e', 'k',
  's'
]
[ 10, 20, 30 ]




Reffered: https://www.geeksforgeeks.org


JavaScript

Related
What are Classes in ES6 ? What are Classes in ES6 ?
How do we use the encodeURIComponent() function in JavaScript ? How do we use the encodeURIComponent() function in JavaScript ?
How does the JSON.parse() method works in JavaScript ? How does the JSON.parse() method works in JavaScript ?
How the Array.unshift() method works in JavaScript ? How the Array.unshift() method works in JavaScript ?
How to Get a Value from a JSON Array in JavaScript ? How to Get a Value from a JSON Array in JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12