Hope this isn't too much of a repeating question, I've checked around seen similar but can't seem to solve my issue.
I have a JS object:
var option1Data = {
option: 'Yes',
numberOfPeople: 3,
gender: {} ,
region: {}
};
I want to check if an item is in gender, if not add and set to 1 else increment into. Note that appending it in is important.
Can someone kindly tell me whats wrong:
var input = 'female'; //for purposes of this example
var processGender = function(input) {
if(option1Data['gender'].hasOwnProperty(input)) {
option1Data['gender'][input]++;
}else {
option1Data['gender'][input] = 1;
}
};
User.find({_id: item['userID']}, {gender: 1, country:1}, function(req, foundUser) {
processGender(foundUser[0]['gender']);
});