Skip to content

Instantly share code, notes, and snippets.

@mig82
Last active February 5, 2020 10:08
Show Gist options
  • Save mig82/2427b8db75f609d30a96fbc6cad9f361 to your computer and use it in GitHub Desktop.
Save mig82/2427b8db75f609d30a96fbc6cad9f361 to your computer and use it in GitHub Desktop.
A Javascript post-processor for Fabric which converts a property from an object into an array of objects.
/*
* Convert something like mymap: {foo: 0, bar: 1, qux:2} into
* myarr: [{foo: 0}, {bar: 1}, {qux:2}] */
function mapToArray(propName){
var res = resultToJSON(result);
var map = res[propName];
var array = [];
for(r in map){
var obj = {};
obj[r] = map[r];
array.push(obj);
}
res[propName] = array;
result = jsonToResult(res);
return result;
}
mapToArray("mapPropName");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment