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:
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- How to move an array element from one array position to another in JavaScript?
- How to check whether an array is subset of another array using JavaScript ?
- How to convert Integer array to String array using JavaScript ?
- Difference between array.size() and array.length in JavaScript
- What is the difference between Array.slice() and Array.splice() in JavaScript ?
- How to include a JavaScript file in another JavaScript file ?
- JavaScript Array unshift() Method
- JavaScript Array shift() Method
- JavaScript Array toString() Method
- JavaScript Array reverse() Method
- JavaScript Array sort() Method
- JavaScript Array pop() Method
- JavaScript Array push() Method
- JavaScript Array forEach() Method
- JavaScript Array lastIndexOf() Method
- JavaScript Array slice() Method
- JavaScript Array indexOf() Method
- JavaScript Array isArray() Method
- JavaScript Array filter() Method
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.


