1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JSでループ/連番配列作成の書き方

Posted at

はじめに

JavaScript でとりあえずループさせたい、とりあえず連番の配列を作成したいという備忘録です。

forEach

[...Array(4)].forEach((_, i) => { console.log(i); });

log
image.png

連番配列作成

[...Array(4).keys()]

log
image.png

[...Array(4)]

とすると、配列の中身がundefinedになるので注意!

log
image.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?