javascript array filter what if no matches code example
Example 1: javascript object filter
function objectFilter = (obj, predicate) =>
Object.keys(obj)
.filter( key => predicate(obj[key]) )
.reduce( (res, key) => (res[key] = obj[key], res), {} );
var scores = {
John: 2, Sarah: 3, Janet: 1
};
var filtered = objectFilter(scores, num => num > 1);
console.log(filtered);
Example 2: javascript array filter
run.addEventListener("click", function () {
let array = [];
people.forEach((elem) => {
if (elem.age > 18) {
array.push(elem);
} else {
("");
}
});
console.log(array);
});