I'm trying to build a new object from an old object recursively like:
var arr = {};
var markCheckBoxes = function(obj){
var trackArr = new Array();
for(var prop in obj){
if(!!obj[i] && typeof(obj[i])=="object"){
trackArr.push(i);
markCheckBoxes(obj[i]);
trackArr.pop();
}
else{
var str = trackArr.join(".") + "." + i;
arr[str] = true;
}
}
};
But this creates a flat object. For example if obj
is:
obj = {
prop1: {
subprop1: "text",
subprop2: "extra"
}, prop2:{
subprop: {another: 3}
}
}
Then the above function creates an object with keys:
{
"prop1.subprop1": true,
"prop1.subprop2": true,
"prop2.subprop.another": true
}