I'm getting this exception in the following code: TypeError: Cannot read property 'toString' of undefined
for (var key in obj) {
var val = obj[key];
var s = val.toString();
}
How is it possible for val to be undefined in this code?
I don't have a log of the actual data, so I'm not sure what was in obj, but it was constructed from JSON and I don't have the JSON input.
This is the actual full code:
function deepMatchKeyword(obj, keyword) {
for (var key in obj) {
var val = obj[key];
if (typeof val == 'object' && !(val instanceof Array)) {
if (deepMatchKeyword(val, keyword))
return true;
} else {
var s = val.toString();
if (s.toLowerCase().includes(keyword))
return true;
}
}
return false;
}