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”} ]
const reducedfilter =(data, keys, func)=>{
data.filter(func).map(el =>{
keys.reduce((acc, key)=>{
acc[key] = el[key];
return acc
},{})
)
}
reducefilter(data, ['id', 'name'], item => item.age > 24)
Code Example |
---|
:: |
:: |
:: |
Javascript :: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
:: |
Javascript :: |
Javascript :: |
:: |
:: |
:: |
:: |
:: |