Skip to content

Instantly share code, notes, and snippets.

@riston
Last active August 29, 2015 14:18
Show Gist options
  • Save riston/9d2fafe3c9869d9ae79d to your computer and use it in GitHub Desktop.
Save riston/9d2fafe3c9869d9ae79d to your computer and use it in GitHub Desktop.
Transforming object into array
var requests = { docs: [ 'hello' ], boards: [ 'R404' ] };
var fetchResultTransform = function (requests)
{
var resource = [];
Object.keys(requests).forEach(function (colName)
{
requests[colName].forEach(function (docName)
{
resource.push({ "colName": colName, "docName": docName });
});
});
return resource;
}
console.log(fetchResultTransform(requests));
requests = { docs: { hello: 1 }, boards: { R404: 7464 }, O1232132: { R21321: 12 } };
var subscribeResultTransform = function (requests)
{
var resource = [];
Object.keys(requests).forEach(function (colName)
{
var collection = requests[colName];
Object.keys(collection).forEach(function (docName)
{
resource.push({
"colName": colName,
"docName": docName,
});
});
});
return resource;
};
console.log(subscribeResultTransform(requests));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment