Javascript examples for Array:forEach
Array map and forEach
<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>