配列とかおれおれAdvent Calendar2018 – 03日目 コンストラクターの引数に複数の値を与えるとそれらを要素に持つ配列が新規作成される一方で、 数値をひとつだけを与えた場合、要素数がその数値であるが中身が空の配列が作成されます。 console.log(Array(11, 22, 33)); // => [ 11, 22, 33 ] console.log(Array('1')); // => [ '1' ] // [3]にならない console.log(Array(3)); // => [ <3 empty items> ]
![Array(3)の代わりにArray.of(3)を使おう。(配列とかおれおれAdvent Calendar2018 – 03日目) | Ginpen.com](https://cdn-ak-scissors.b.st-hatena.com/image/square/de4af7f62b39439905833504e59ba1e153be6d8b/height=288;version=1;width=512/https%3A%2F%2Fginpen.com%2Fwp-content%2Fthemes%2Fginpen-theme%2Fimg%2Ficon-512.png)