filter array of objects with js as search code example
Example 1: filter array by keyword
var data = [
{email: "[email protected]",nama:"User A", Level:"Super Admin"},
{email: "[email protected]",nama:"User B", Level:"Super Admin"},
{email: "[email protected]",nama:"User C", Level:"Standart"},
{email: "[email protected]",nama:"User D", Level:"Standart"},
{email: "[email protected]",nama:"User E", Level:"Admin"},
{email: "[email protected]",nama:"User F", Level:"Standart"}
];
var filter = "Level";
var keyword = "Standart";
var filteredData = data.filter(function(obj) {
return obj[filter] === keyword;
});
console.log(filteredData);
Example 2: javascript filter array of objects
function isBigEnough(value) {
return value >= 10
}
let filtered = [12, 5, 8, 130, 44].filter(isBigEnough)