简体   繁体   中英

To find intersection between a Object and array

I'm beginner to javascript.

How to find intersection between a array and object in javascript.

Lets take:

   var use = [{name:'jony'}, {name: 'raja'}, {name: 'papy'}];

And array as:

   var now = ['jony', 'raja', 'singh'];

Now how can I get result as

   var result = ['jony', 'raja'];
var result = use.filter(function(e) {
    return now.indexOf(e.name) > -1;
}).map(function(e) { return e.name; });

console.log(result);  // ["jony", "raja"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM