📌  相关文章
📜  如何在javascript代码示例中按数组过滤对象列表

📅  最后修改于: 2022-03-11 15:02:50.478000             🧑  作者: Mango

代码示例4
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)