I have 2 arrays like this ...
var heroes = [{
name: "Batman",
franchise: "DC"
},
{
name: "Ironman",
franchise: "Marvel"
},
{
name: "Thor",
franchise: "Marvel"
},
{
name: "Superman",
franchise: "DC"
}
];
var stars = ["Thor", "Superman"];
var marvelHeroes = heroes.filter(function(hero) {
return stars.indexOf(hero.name) >= 0;
});
console.log(marvelHeroes);
This code is returning 'undefined'. So essentially I am trying to filter an array against values in another array.
Can someone please advise what am I doing wrong ? Thanks
My expected output is an array of objects like the following ...
[
{name: "Thor", franchise: "Marvel"},
{name: "Superman", franchise: "DC"}
];
I have seen a similar question here, but that solution is not working for me ...
heroare you trying to select? Select withhero[index].name