Given an input Object, loop over the Object and print its keys using console.log(). code example
Example 1: javascript object keys foreach
var lunch = {
sandwich: 'ham',
snack: 'chips',
drink: 'soda',
desert: 'cookie',
guests: 3,
alcohol: false,
};
Object.keys(lunch).forEach(function (item) {
console.log(item);
console.log(lunch[item]);
});
Example 2: obj[key].includes is not a function
var aa = [{id: 1,type: 1,status: 1,name: 'txt'},{id: 2,type: 1,status: 1,name: 'txt'},{id: 3,type: 0,status: 0,name: 'txt'}];
function filterIt(arr, searchKey) {
return arr.filter(function(obj) {
return Object.values(obj).includes(searchKey);
});
}
console.log(filterIt(aa, 'txt'));