Following is an object with some deep properties.
const InitialObj = {
Store: {propsFromStore: {}},
Market: {propsFromMarket: {}},
GoDown: {propsFromDown: {}},
fruits: {store_c: "Store", otherProp1: {store_e: "Store", otherSubProp1: {}}, otherProp2: {}},
vegetables: {market_d: "Market", otherProp1: {otherSubProp1: {godown_r: "GoDown", }}},
fancy:{store_t: "Store", market_d: "Market", otherProp1: {otherSubProp1: {godown_r: "GoDown", }}},
}
Where ever you see "Store", "Market" or "GoDown", it should get replaced with values from the following object - no matter how deep they are.
// these values are not separate. there are part of the above initialObj.
//These values should replace Where ever you see "Store", "Market" or "GoDown", no matter how deep they are.
// The following values should be obtained from the above initialObj. & Not as a separate object.
Store: {propsFromStore: {}},
Market: {propsFromMarket: {}},
GoDown: {propsFromDown: {}},
So that the final result will be:
expected result
// this is what we get when the initialObj is transformed
// note that after removing all the occurences of "Store"/ "Market" / "GoDown"; these values will be removed so that final result looks like this. (with all placeholders replaced"
const finalExpectedResult = {
fruits: {store_c: {propsFromStore: {}, otherProps...}, otherProp1: {store_e: {propsFromStore: {}, otherProps...}, otherSubProp1: {}}, otherProp2: {}},
vegetables: {market_d: {propsFromMarket: {}, otherProps...}, otherProp1: {otherSubProp1: {godown_r: {propsFromDown: {}, otherProps...}, }}},
fancy:{store_t: {propsFromStore: {}, otherProps...}, market_d: {propsFromMarket: {}, otherProps...}, otherProp1: {otherSubProp1: {godown_r: {propsFromDown: {}, otherProps...}, }}},
}
Note that this should replace all the deep occurences of "Store", "Market" or "GoDown" with corresponding values
See Question&Answers more detail:
os