Home >>JavaScript Array Reference >JavaScript Array from() Method

JavaScript Array from() Method

JavaScript Array from() Method

The JavaScript Array from() method is an inbuilt function in JavaScript which returns an array object from a given array with a length property or an iterable object. In case of string, every alphabet of the string is converted of the new array to an element and new array instance simple take the elements of the given array in case of integer values.

Syntax
Array.from(object, mapFunction, thisValue)

Parameter Values

Property Description
object It required the object to convert to an array
mapFunction It is optional parameter, used for a map function to call on each item of the array
thisValue It is optional parameter used for a value to use as this when executing the mapFunction

Browser Support

Method Chrome Edge Firefox Safari Opera
from() 45.0 12.0 32.0 9 25.0
Here is an example of JavaScript array from() Method:
<!DOCTYPE html>
<html>
<body>
<p id="arrfrom"></p>
<script>
var myArrfrm = Array.from("123456");
document.getElementById("arrfrom").innerHTML = myArrfrm;
</script>
</body>
</html>
Output:

Example 2:
<!DOCTYPE html>
<html>
<body>
<p id="arrfrom1"></p>
<script>
var myArrfrm1 = Array.from("phptpointtraining");
document.getElementById("arrfrom1").innerHTML = myArrfrm1;
</script>
</body>
</html>
Output:


No Sidebar ads