JavaScript の range の書き方。

これは知らなかった。map もついでに出来てしまう。

Array.from({ length: 5 }, (_, i) => i * 2)

今まではこっちを使っていたけど、ちょっと技巧に走りすぎている感がある。

[...Array(5).keys()].map(i => i * 2)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#using_arrow_functions_and_array.from

Reply to this note

Please Login to reply.

Discussion

No replies yet.