Skip to main content

Command Palette

Search for a command to run...

Do You Know JS? Array.from In 60 Seconds

Updated
1 min read
Do You Know JS? Array.from In 60 Seconds
A

I have the ability to put together high performance and scalable applications which are fit for purpose, functionality correct and meet user precise needs.

What is array.from?

Array.from is a JavaScript method that make you create an array from any iterate-able object i.e from a String, Set, Map, NodeList basically any object that has a length property.

Examples

// Array from string
Array.from('bar');
// [ "b", "a", "r" ]

// Array from Set
const set = new Set(['foo', 'bar', 'baz', 'foo']);
Array.from(set);
// [ "foo", "bar", "baz" ]

Spoiler Alert

A method that comes with such a power has it limitation also, it is not compatible with IE Internet Explorer, but tools like Babel will translate it.

Exploring the power Array.From method brings benefit of JavaScript language to the fullest and limit the lines of codes.

Sources

Array.from()

JavaScript Array.from()