📌  相关文章
📜  可以在javascript代码示例中对对象使用过滤器

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

代码示例1
var heroes = [
    {name: “Batman”, franchise: “DC”},
    {name: “Ironman”, franchise: “Marvel”},
    {name: “Thor”, franchise: “Marvel”},
    {name: “Superman”, franchise: “DC”}
];

var marvelHeroes =  heroes.filter(function(hero) {
    return hero.franchise == “Marvel”;
});

// [ {name: “Ironman”, franchise: “Marvel”}, {name: “Thor”, franchise: “Marvel”} ]