I am attempting to check if the calendar
and tpoint
keys have values associated with them.
At first I tried to just check to see if calendar
and tpoint
keys were included, but then I realized they always would be as they are keys. The reason I am wanting to check to see if the calendar
and tpoint
keys have values because sometimes they won't.
My attempt is below the packageContents
object below.
Does anyone know how I can check if the keys have values?
var packageContents = {
'packages': [
{
'price': '32',
'name': 'Gold Bundle Package',
'calendar': {
'type': '2year',
'color': 'Brushed Nickel',
},
'tpoint': {
'type': 'Gold',
'touches': '21',
'years': '7',
}
},
{
'price': '23',
'name': 'Bronze Bundle Package',
'calendar': {
'type': '2year',
'color': 'Brushed Nickel',
},
'tpoint': {
'type': 'Bronze',
'touches': '9',
'years': '7',
}
}
]
};
packageContents['packages'].forEach(function (bun) {
if (bun['calendar'].length >= 1 && bun['tpoint'].length >= 1) {
var bundleSet;
console.log(bundleSet);
console.log('Working');
}
});
Edit:
var packageContents = {
'packages': [
{
'price': '23',
'name': 'Bronze Bundle Package',
'calendar': {
'type': '2year',
'color': 'Brushed Nickel',
},
'tpoint': {
'type': '',
'touches': '',
'years': '',
}
}
]
};
var bundleSet = '';
packageContents['packages'].forEach(function (obj) {
if (typeof obj.calendar !== 'undefined' && typeof obj.tpoint !== 'undefined') {
bundleSet = "Bundle";
}
else {
bundleSet = "not bundle"
}
console.log(bundleSet);
});