I have an object list:
var myObj = {
obj1: {name: "bob", employed: true},
obj2: {name: "dave", employed: false},
obj3: {name: "james", employed: true},
}
What is the most efficient/elegant way to iterate through the object list and count how many objects are equal employed: true
. Is there a short way to write this? I was thinking of implementing it like below:
const countEmployed = () => {
for (let key in myObj) {
if (myObj .hasOwnProperty(key)) {
}
}
}