I am really struggling to get to the names in this javascript object. Please could someone help me? What I want is to get someones name and if their "attending' status is true push their name into the "going" array and if their status is false push their name into the "not going" array.
The object is below and then the code I have written so far is below that. I don't know what to do when I get to the name level as they're different names...
"HmS7XXPFoCQ7GmvfcCnF": {
"invitees": {
"gus": {
"attending": true,
"invitedBy": "will"
},
"margot": {
"attending": "false",
"invitedBy": "gus"
}
}
}
here is my code:
Object.keys(invitees).map(function(keyName, i) {
if (invitees[keyName] === true) {
//this is causing problems as the last name will be displayed as august,
inviteesGoing.push(`${keyName}, `);
} else if (invitees[keyName] === false) {
//this is causing problems as the last name will be displayed as august,
inviteesNotGoing.push(`${keyName}, `);
} else {
console.error("undetermind user status:" + keyName);
}
});
thanks
margot.attending = “false”which is a strong but you are comparing it tofalseas a Boolean in your if statement..joinmap()and the function doesn't return anything and you don't use the result, you should be usingforEach().