Skip to content

Instantly share code, notes, and snippets.

@cognitom
Created June 29, 2016 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cognitom/d85c3d03a06c65b9ad0934546bf86fcc to your computer and use it in GitHub Desktop.
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
// 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