Let's assume we have an array of object
const array = [ { id: 1, name: 'My first object', value: 5 }, { id: 1, name: 'My second object', value: 10 }, { id: 1, name: 'My third object', value: 20 } ]
We want to calculate the sum of the field 'value'
const sum = array.map((item) => { return item.value; }).reduce((sum, current) => sum + current, 0); console.log(sum)
will return 35
This syntax is much classier than a for loop, isn't it? ;)
Comments
Williamzob e*m*i*.*.*.*.*6*8@gmail.com
Jimmywoody a*a*i*w*e*1*8*8*@rambler.ru
химия купить...
JefferyNaw s*.*r*o*z*.*t*c@gmail.com
Robertnub v*w*l*b*l*c*m*9*4*@rambler.ru
StevenHAx s*g*d*h*2*@gmail.com
KeithTuh w*n*o*u*h*a*9*6*4@rambler.ru
Tommypam c*m*n*a*e*9*8*4@rambler.ru
MichaelPhove l*n*d*n*j*m*h*1*7*9*@rambler.ru
JamesCaf s*g*7*9*7*9*@gmail.com
RichardApell i*.*.*.*.*a*r*i*e*v*a@gmail.com
Write comments