📅  最后修改于: 2022-03-11 15:02:50.478000             🧑  作者: Mango
var array = ['cat','dog','fish','goat']
var objects = [{pet:'cat', color:'brown'},{pet:'dog', color:'black'},{pet:'gecko', color:'green'}]
//finds the objects that match something in the list with the key pet.
var filteredObjects = objects.filter(function(obj){
return array.indexOf((obj.pet).toString()) > -1;
});
console.log(filteredObjects)