I have a javascript object with multiple nested objects like this :
var stats = {
bookServed: {
redis: 90,
s3: 90,
signedUrl: 70
},
errors: {
redis: {
bookService: 70,
mapi: 50,
capi: 30
},
AWS: {
signedUrl: 70,
downloadBook: 50,
searchBook: 10
},
decryption: 60
}
};
What would be the cleanest way to iterate through all its properties and set each value to 0 for instance. I wrote something like this
for (var property in stats) {
if (stats.hasOwnProperty(property)) {
if (typeof property === "object") {
for (var sub_property in property)
if (property.hasOwnProperty(sub_property)) {
sub_property = 0
}
} else {
property = 0;
}
}
}
I'm willing to use a library like underscore.js to do the task properly.