Sum of Array with filter and reduce - Javascript Array

Javascript examples for Array:reduce

Description

Sum of Array with filter and reduce

Demo Code

ResultView the demo in separate window

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

Related Tutorials