I am looking to replicate certain fields within an object in other fields of the same object, similar to the concept demonstrated below:
var customers = {
apple: {
papa: {
en: "cool"
}
},
oranges: {
papa: {
en: "cool"
}
}
};
function deepCopyEn(src) {
if (src.hasOwnProperty("en")) {
src.fr = src.en;
src.es = src.en;
}
else {
if (src.constructor === Array) {
for (var i = 0; i < src.length; i++) {
deepCopyEn(src[i]);
}
}
else {
for (var prop in src) {
if(src.hasOwnProperty(prop)) {
deepCopyEn(src[prop]);
}
}
}
}
}
deepCopyEn(customers);
console.log(customers);
However, I encountered an issue when attempting to apply the same concept to a class with an array and another field. The function did not work, resulting in the error: RangeError: Maximum call stack size exceeded. For reference, you can view an example here. Can someone assist me in updating my function to resolve this issue?