Skip to content
Related Articles

Related Articles

Improve Article

JavaScript | Array from() Method

  • Last Updated : 01 Mar, 2019

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>

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>

Output :

Supported Browsers:

  • Google Chrome
  • Mozilla Firefox
  • Edge
  • Opera
  • Safari



My Personal Notes arrow_drop_up
Recommended Articles
Page :