Home > shorts > JavaScript Array.from() method

JavaScript Array.from() method

The Array.from() static method creates a new, shallow-copied Array instance from an array-like or iterable object.

It has an optional parameter mapFn, which allows you to execute a map() function on each element of the array being created.

const data = ["šŸ", "šŸ", "šŸ‹"]
const secondArgument = (x => "Iā¤ļø" + x)
Array.from(data, secondArgument) // ["Iā¤ļøšŸ", "Iā¤ļøšŸ", "Iā¤ļøšŸ‹"]

Check the demo here => CodePen

Ā© 2021, Andrew Losseff