I have the following set up: fetch some documents from Mongo. If there is a 'gap' in the dates then compute dates and insert missing rows. An additional requirement is that if the most recent user entry is "Yes", then I should copy the object into each of the inserted rows, i.e. pre-fill some data. Here's a simple example of the object:
{
"section1": {},
"section2": {},
"section3": {},
"section4": {
"question1": "Y",
"question2": "N",
"question3": "true",
"question4": "false",
"question5": "05/15/2017"
},
"section5": {}
}
So, if I understand things correctly, I can't simply do something like:
if(oldObj.section4.question1==="Y"){
newObj.section4 = oldObj.section4; //copy the enter sub object
}
JS copies 'by reference'. I need to deep copy oldObj.section4 entirely. It doesn't look like there is an simple way to do this. NPM has a deep copy module that I might take a look at. Any advice would be appreciated. Is this the correct approach?