JavaScript Array from() method creates a new array from an array-like or iterable object. This method returns an array from any object with a length property.
Array.from(object, mapFunction, thisValue)
You can only use it as Array.from().
JavaScript Array from()
Simple example code creating a new array from string.
<!DOCTYPE html>
<html>
<body>
<script>
var str = "abc";
let res = Array.from(str);
console.log(res);
</script>
</body>
</html>
Output:
The method with the Mapping Function
console.log(Array.from('foo'));
// output: Array ["f", "o", "o"]
console.log(Array.from([1, 2, 3], x => x + x));
// output: Array [2, 4, 6]
Do comment if you have any doubts or suggestions on this Js array method tutorial.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version