<!DOCTYPE html> <html> <body> <p id="xyz"></p> <script> let str = "codescracker"; const arr = Array.from(str); document.getElementById("xyz").innerHTML = arr; </script> </body> </html>
Note - The from() is a static method. Static methods are called by classes, whereas dynamic methods are called by objects.
Array.from(object, mapFn, thisArg)
The object refers to an array-like or iterable object, that is going to convert into an array.
The mapFn refers to a map function. Use this parameter, when you need to call a function on every element of the specified array.
The thisArg refers to the value that will be used as this for the mapFn.
« Previous Tutorial Next Tutorial »
Like/Share Us on Facebook 😋