filter out objects in array based on value code example
Example 1: js filter array of objects by value
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”;
});
Example 2: javascript array filter elements greater than
function isGreater(element, index, array) {
return (element >= 10);
}
let testElemets = [12, 5, 8, 130, 44].filter(isGreater);
console.log("Test Value : " + testElemets );