JavaScript | Array from() Method
The JavaScript Array from() method returns an Array object from any object with a length property or an iterable object.
Syntax :
Array.from(object, mapFunction, thisValue)
Parameter :
- object : This Parameter is required to specify the object to convert to an array.
- mapFunction : This Parameter specify the map function to call on each item of the array.
- currentIndex : This Parameter specify the array index of the current element.
- thisValue : This Parameter specify the value to use as this when executing the mapFunction.
Return Value: It returns an array object.
Example-1:
<!DOCTYPE html> <html> <body> <center> <h2>GeeksForGeeks </h2> <p>Create an Array from a String:</p> <p id="demo"></p> <script> var myArr = Array.from( "GeeksForGeeks"); document.getElementById( "demo").innerHTML = myArr; </script> </center> </body> </html> |
chevron_right
filter_none
Output:

Example-2:
<!DOCTYPE html> <html> <body> <center> <h2>GeeksForGeeks</h2> <p>Create an Array from a String: "45878965412365" </p> <p id="demo"></p> <script> var myArr = Array.from("45878965412365"); document.getElementById( "demo").innerHTML = myArr; </script> </center> </body> </html> |
chevron_right
filter_none
Output :

Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Edge
- Opera
- Safari
Recommended Posts:
- JavaScript | Array map() Method
- JavaScript | Array.from() method
- JavaScript | Array.splice() Method
- JavaScript | Array valueOf() Method
- JavaScript | Array.fill() Method
- JavaScript | Array.findIndex() Method
- JavaScript | Array.find() Method
- JavaScript | Array reduce() Method
- JavaScript | array.entries() Method
- JavaScript | Array.join() Method
- indexOf method in an object array in JavaScript
- How to get the elements of one array which are not present in another array using JavaScript?
- JavaScript | Array pop()
- RMS Value Of Array in JavaScript
- JavaScript | Array toString()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



