Last active
February 5, 2020 10:08
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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