LoginSignup
1
1

【JavaScript】【jquery】指定した回数だけ回す。$.each([...Array(num).keys()]を使う

Last updated at Posted at 2022-04-27

コード

連番数値の配列を作る


const num = 15;

console.log([...Array(num).keys()]);

// 1から始めたいなら
console.log([...Array(num).keys()].map(n => ++n));

$.each([...Array(fields.length).keys()], function(_,i) {
    console.log(i);
})

結果

[
   0,  1,  2, 3,  4,  5,
   6,  7,  8, 9, 10, 11,
  12, 13, 14
]


[
   1,  2,  3,  4,  5,  6,
   7,  8,  9, 10, 11, 12,
  13, 14, 15
]

1
1
0

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
1
1