YanoRyuichi.com/
Wiki
Blog
GitHub
Sandbox
開始行:
* forEach map filter reduce [#kb95b49a]
** map [#qe059aa5]
let nums = [ 1, 2, 3, 4 ];
let ret = nums.map((n) => { return n * 2; });
console.log(ret);
=> [ 2, 4, 6, 8 ]
** filter [#f04fb4a7]
let nums = [ 1, 2, 3, 4 ];
let ret = nums.filter((n) => { return n % 2 === 0 ? true...
console.log(ret);
=> [ 2, 4 ]
let nums = [ 1, 2, 3, 4 ];
let ret = nums.filter((n) => { return true; });
console.log(ret);
=> [ 1, 2, 3, 4 ]
let nums = [ 1, 2, 3, 4 ];
let ret = nums.filter((n) => { return false; });
console.log(ret);
=> []
** reduce [#r8169995]
let total = [0, 1, 2, 3].reduce((sum, value) => sum + va...
console.log(total);
=> 6 // = 0 + 1 + 2 + 3
let total = [0, 1, 2, 3].reduce((sum, value) => sum + va...
console.log(total);
=> 106 // = 100 + 0 + 1 + 2 + 3
let result = ['A', 'B', 'C'].reduce((str, value) => str ...
console.log(result);
=> ABC
let result = ['A', 'B', 'C'].reduce((str, value) => str ...
console.log(result);
=> XABC
*** 参考 [#r4b9996a]
https://developer.mozilla.org/ja/docs/Web/JavaScript/Refe...
終了行:
* forEach map filter reduce [#kb95b49a]
** map [#qe059aa5]
let nums = [ 1, 2, 3, 4 ];
let ret = nums.map((n) => { return n * 2; });
console.log(ret);
=> [ 2, 4, 6, 8 ]
** filter [#f04fb4a7]
let nums = [ 1, 2, 3, 4 ];
let ret = nums.filter((n) => { return n % 2 === 0 ? true...
console.log(ret);
=> [ 2, 4 ]
let nums = [ 1, 2, 3, 4 ];
let ret = nums.filter((n) => { return true; });
console.log(ret);
=> [ 1, 2, 3, 4 ]
let nums = [ 1, 2, 3, 4 ];
let ret = nums.filter((n) => { return false; });
console.log(ret);
=> []
** reduce [#r8169995]
let total = [0, 1, 2, 3].reduce((sum, value) => sum + va...
console.log(total);
=> 6 // = 0 + 1 + 2 + 3
let total = [0, 1, 2, 3].reduce((sum, value) => sum + va...
console.log(total);
=> 106 // = 100 + 0 + 1 + 2 + 3
let result = ['A', 'B', 'C'].reduce((str, value) => str ...
console.log(result);
=> ABC
let result = ['A', 'B', 'C'].reduce((str, value) => str ...
console.log(result);
=> XABC
*** 参考 [#r4b9996a]
https://developer.mozilla.org/ja/docs/Web/JavaScript/Refe...
ページ名: