Array map and forEach - Javascript Array

Javascript examples for Array:forEach

Description

Array map and forEach

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/* w ww . j  a v a 2 s .co  m*/
var fields = ['js', 'cpp'];
var data = [{'js': 1, 'cpp': 2}, {'js': 3, }];
var items = data.map(function(o) {
   fields.forEach(function(field, i) {
     if (field in o) {
       return o;
    }
  })
})
console.log(items);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials