reduce() ile dizideki tüm değerlerin toplamını bulmak


( ! ) Notice: Undefined index: description in /home/prototurk.com/public_html/app/controller/demo.php on line 171
Call Stack
#TimeMemoryFunctionLocation
10.0002360288{main}( ).../index.php:0
20.0043442136require( '/home/prototurk.com/public_html/app/controller/demo.php' ).../index.php:101

Prototürk'e geri dön
let sum = [0, 1, 2, 3].reduce(function (accumulator, currentValue) {
  return accumulator + currentValue
}, 0)
console.log(sum) // 6

// alternatif olarak arrow function ile şöyle yazılabilir
let total = [ 0, 1, 2, 3 ].reduce(( accumulator, currentValue ) => accumulator + currentValue, 0)
console.log(total) // 6