JavaScript

Array.from data in JavaScript

JavaScriptArraysArray.fromintermediate

What this snippet does

Array.from with a map function is the cleanest way to generate arrays of computed values without a loop.

Expected output

[ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 ]
[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]

Why practise typing this

Typing arrays code builds muscle memory for the symbols and indentation JavaScript uses most, which prose-based typing tests never cover. DevType measures your words per minute and accuracy on this snippet and tracks the individual characters you mistype, so later lessons can target them.

More JavaScript practice

Browse all JavaScript snippets →