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

More than 3 years have passed since last update.

連番の初期値リストを作る

Posted at

angular(typescript)で
1 2 3 ・・・ 100など連番の初期値リストを作る


  ageList = [...Array(10).keys()].map((i) => {
    i++;
    return i * 10;
  });
  monthList = [...Array(12).keys()].map((i) => ++i);

<div>
  <span *ngFor="let age of ageList">{{ age }}歳</span>
</div>
<div>
  <span *ngFor="let month of monthList">{{ month }}月</span>
</div>

スクリーンショット 2020-05-24 12.10.34.png

0から始めたいときは++iをi++にする

... を使った書き方については
「…」←これ、ただの省略記号かと思ってました。(Spread operatorのお話)
スプレッド構文

keysについては
Array.prototype.keys()

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