Javascript examples for Array:map
Use array map(), filter(), indexOf()
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*w ww .j av a 2 s . c o m*/ var ids = [1,22,16] var locationInfo = [{name:'loc1',id:1}, {name:'loc2',id:22},{name:'loc3',id:40}]; var locs = locationInfo .map(item=>ids.indexOf(item.id) > -1 ? item: undefined) .filter(e=>e); console.log(locs); } </script> </head> <body> </body> </html>