Created
June 29, 2016 03:39
-
-
Save cognitom/d85c3d03a06c65b9ad0934546bf86fcc to your computer and use it in GitHub Desktop.
How to get [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ES6 | |
[...Array(10).keys()] | |
Array(10).map((n, i) => i) | |
Array.from(Array(10).keys()) | |
Array.from({ length:10 }, (v, i) => i) | |
// ES5 | |
Array(10).map(function(n, i) { return i }) | |
// Oldies | |
var a = []; for (var i = 0; i < 10; i++) a.push(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment