1var heroes = [
2 {name: “Batman”, franchise: “DC”},
3 {name: “Ironman”, franchise: “Marvel”},
4 {name: “Thor”, franchise: “Marvel”},
5 {name: “Superman”, franchise: “DC”}
6];
7
8var marvelHeroes = heroes.filter(function(hero) {
9 return hero.franchise == “Marvel”;
10});
11
12// [ {name: “Ironman”, franchise: “Marvel”}, {name: “Thor”, franchise: “Marvel”} ]
1const raw = {
2 item1: { key: 'sdfd', value:'sdfd' },
3 item2: { key: 'sdfd', value:'sdfd' },
4 item3: { key: 'sdfd', value:'sdfd' }
5};
6
7const allowed = ['item1', 'item3'];
8
9const filtered = Object.keys(raw)
10 .filter(key => allowed.includes(key))
11 .reduce((obj, key) => {
12 obj[key] = raw[key];
13 return obj;
14 }, {});
15
16console.log(filtered);