This is the recusive (barely tested) version that keith recommended not using. However, if you know that your data structure does not contain any infinite loop scenarios it could be of use. It’s also possible to store certain values (e.g. uid) to detect recursion, but I didn’t feel that to be a necessary exercise here.
function reReduce(obj, prop) {
var res = obj.get(prop);
if(res && res.hasOwnProperty('get')) {
return res.listProperties().reduce((object, property) => ( object[property] = reReduce(res,property) , object ), {});
}
else {
return res;
}
}
var result = properties.data.get(0, properties.data.length()).map(item => item.listProperties().reduce((object, property) => ( object[property] = reReduce(item,property) , object ), {}));