LoginSignup
1
0

More than 1 year has passed since last update.

【メモ】JSの分かりづらい記法のメモ

Last updated at Posted at 2023-05-02

※コメント欄で指摘があったため追記しました。

Array.from()

いずれも実行結果は同じ

// ES6の構文
const arr = Array.from({ length: 10 }, (_, i) => i)
console.log(arr) // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

// スプレッド演算子の構文
const arr = [...Array(10).keys()]
console.log(arr) // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

// 従来の記法
const arr2 = []
for (let i = 0; i < 10; i++) {
  arr2.push(i)
}
console.log(arr2) // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
1
0
2

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