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 ]
Recommended Articles