168
116

More than 3 years have passed since last update.

連番の数字の配列を作成(es2015 ver)

Last updated at Posted at 2016-09-11

tl;dr (追記)

// 0始まりでよいなら・・・
const minitues = [...Array(60).keys()]
// => [0, 1, 2, 3,....,59]

// 1始まりにしたい、etc.なら・・・・
const minitues = [...Array(60).keys()].map(i => ++i)
// => [1, 2, 3, 4,....,60]
  • コメント欄で教えてもらったやつ。
  • コメント主が退会して表示されなくなったため転記

例えば 0,1,...,59と続く配列がほしいなら

const minitues = Array.from(new Array(60)).map((v,i) => i)
// [0, 1, 2, 3,....,59]
  • (new Array(60)).map(...)だとうまくいかない

1から始めたいなら

const minitues = Array.from(new Array(60)).map((v,i)=> i + 1)

coffeescriptだと。。。

minitues = [0...60]
168
116
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
168
116