from() Function is used to return an Array from any object.
Let us say, we a number 5829 and we want each number as a unique array element, 5, 8, 2 and 9.
And from() function helps us achieve the above array.
Let us see in the below example.
<html> <body> <script> var x = "5829" var y = Array.from(x) document.write(y) </script> </body> </html>
And we have created an array of individual elements.
Just remember to take 5829 as a String.
var x = "5829"
And Array.from() will convert it to an array with four elements.
You can also call a map() if you want to perform some calculations. You can pass it as second argument.
Say you want to check which value is equivalent to 8.
Let us see in the below example.
<html> <body> <script> function numberCheck(i) { return i == 8 } var x = "5829" var y = Array.from(x, numberCheck) document.write(y) </script> </body> </html>