DEV Community 👩‍💻👨‍💻

skptricks
skptricks

Posted on

Understanding Array.From() In JavaScript

Post Link : Understanding Array.From() In JavaScript

This tutorial explains how to use Array.from() function in javascript. The Array.from() method creates a new, shallow-copied Array instance from an array-like or iterable object.

Syntax :
Array.from(object, mapFunction, thisValue)

Parameter Description
object : Required. The object to convert to an array
mapFunction : Optional. A map function to call on each item of the array
thisValue : Optional. A value to use as this when executing the mapFunction

Understanding Array.from() in JavaScript

Convert String to Array :
var a = Array.from('Skptricks');
console.log(a)

Output:-

Array ["S", "k", "p", "t", "r", "i", "c", "k", "s"]

Top comments (1)

Collapse
michaelhonan profile image
Michael

I don't mean to be rude, but why make this post when MDN explains it quite well (almost exactly the same as how you did).

🤔 Did you know?

 
📚 You can adjust your experience level in Settings to see more relevant content.