Comments (6)
Array.prototype.fill
doesn't have great support, though:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill#Browser_compatibility
from til.
TIL :)
from til.
Perhaps Array.apply(null, Array(10)).map((n, i) => i)
or Array.apply(null, Array(10)).map(function (n, i) { return i; })
for javascript engines that don't support the arrow functions.
It can also be tweaked for 1..n with Array.apply(null, Array(10)).map((n, i) => i + 1)
I don't understand why the need to use Number
.
from til.
Array.from({length: 10}, (_, i) => i + 1)
is also cool
from til.
const range = len => Array.from(Array(len)).map((_, i) => ++i)
will work too
from til.
Thanks for all the input, I didn't realize there were so many ways to achieve this.
from til.
Related Issues (20)
- List filenames without the diffs HOT 1
- Move The Latest Commit To A New Branch HOT 1
- javascript/random-cannot-be-seeded.md HOT 1
- go/sleep-for-a-duration.md HOT 1
- go/not-so-random.md HOT 1
- "List All The Say Voices" missorted HOT 2
- vim/scrolling-relative-to-the-window.md HOT 1
- JS: Truthiness of Integer Arrays HOT 1
- vim "Wrap With Some Room" precision HOT 4
- elixir/dynamically-generating-atoms is empty HOT 1
- postgres/turn-timing-on.md link is incorrect in README HOT 1
- Automate creation of README.md HOT 4
- Create RSS feed HOT 1
- Your newsletters go to spam
- Compile md files together in one file for easy reading of TILS of each topic HOT 4
- vim-til: file name typo
- sed: missing -n in example
- css: typo HOT 1
- This is an creative idea
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from til.