I have an object similar to the one in the stackblitz linked below and I need to determine if a key is of type Date. If it is, I want to add 3 days to that date. I have successfully implemented this for non-recursive objects, but I am facing challenges with recursive objects. How can I overcome this issue? Efficiency is crucial for me as my real-life objects are large and complex.
myObject = {
aProperty: {
aSetting1: 1,
aSetting2: new Date(),
aSetting3: 3,
aSetting4: 4,
aSetting5: 5
},
bProperty: {
bSetting1: {
bPropertySubSetting: new Date()
},
bSetting2: "bString"
},
cProperty: {
cSetting: new Date()
},
dProperty: new Date()
}
convertButtonClick() {
this.convert(this.myObject);
console.log(this.myObject);
}
convert(obj) {
for (var property in obj) {
if (obj.hasOwnProperty(property)) {
if (obj[property] instanceof Date) {
obj[property].setDate(obj[property].getDate() + 3);
}
}
}
}