Javascript examples for Array:reduce
Sum of Array with filter and reduce
<html> <head> <meta name="viewport" content="width=device-width"> </head> <body> <script> var items=[{my:"1"},{my:"12"},{my:"3"}]; this.totalValue = this.items.filter((item) =>item.my) .map((item) => +item.my) .reduce((sum, current) => sum + current); console.log(this.totalValue); </script> </body>/*w ww . ja v a 2 s . c o m*/ </html>