The Wayback Machine - https://web.archive.org/web/20230705234432/https://www.geeksforgeeks.org/javascript-array-from-method/
Skip to content
Related Articles
Open In App

Related Articles

JavaScript Array from() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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)

Parameters:

  • object: This Parameter is required to specify the object to convert to an array.
  • mapFunction: This Parameter specifies the map function to call on each item of the array.
  • currentIndex: This Parameter specifies the array index of the current element.
  • thisValue: This Parameter specifies the value to use as this when executing the mapFunction.

Return Value: It returns an array object. 

Example 1: In this example, we will be using Array from() method to create an array from the string value.

Javascript




let myArr = Array.from(
    "GeeksForGeeks");
console.log(myArr);

Output

[
  'G', 'e', 'e', 'k',
  's', 'F', 'o', 'r',
  'G', 'e', 'e', 'k',
  's'
]

Example 2: In this example, we will be using Array from() method to create an array from the string value.

Javascript




let myArr = Array.from("45878965412365");
 
console.log(myArr);

Output

[
  '4', '5', '8', '7',
  '8', '9', '6', '5',
  '4', '1', '2', '3',
  '6', '5'
]

 We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.

Supported Browsers:

  • Google Chrome 45 and above
  • Edge 12 and above
  • Firefox 32 and above
  • Opera 32 and above
  • Safari 9 and above

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.

Last Updated : 26 May, 2023
Like Article
Save Article
Similar Reads
Related Tutorials