LoginSignup
0
1

More than 3 years have passed since last update.

reduceとmap

Last updated at Posted at 2020-06-20

備忘録として残します


// reduceは引数で渡された関数を実行し単一の結果を返す

const test = [1,2,3];

const total = test.reduce((acc,cur) => {
  return acc + cur;
})

// accに実行結果が蓄積されていく

console.log(total);

// 結果 6

// mapは配列を返す 

const double = test.map((num) => {
  return num * 2;
})

console.log(double);

// 結果 [2,4,6]

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