I have a JSON object
var values = {"220":{"287":19,"total":19},"":{"240":76,"total":76},"total":95};
and I'm not able to check if values[item]['total'] is defined.
item is variable got from selectbox value, basically I'm trying to make if else statement, I need to check if values[item]['total'] is defined, I have 2 scenarios
item is 220, or another number which goes in "" (json object is generated with php, in this case it has 220 and "", because it doesnt have "color" value, only size, but usally it have correct values)
and in my case item value is the one in {} brackets - for example 287 and 240
This code :
if ( typeof values[item]['total'] === 'undefined' ) {
console.log('undefined');
}
throws: Uncaught TypeError: Cannot read property 'total' of undefined.