Created
November 4, 2019 17:24
-
-
Save leo-bianchi/665b7d0b093d81f7f628c8a758e299e4 to your computer and use it in GitHub Desktop.
Build a custom object from another object.
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
/** | |
* Build a custom json template from another json. | |
* | |
* @param {Object} myObject - Object to be build | |
* @returns {Object} Builded JSON | |
* @module buildJson | |
*/ | |
function buildJson(myObject) { | |
myObject = Object.keys(myObject).map(function(key, index) { | |
let newObject = { | |
'name': key, | |
'label': key.toUpperCase(), | |
'value': myObject[key].replace(/\uFFFD/g, ''), // Replace broken characters | |
'order': index | |
}; | |
return newObject; | |
}); | |
return myObject; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment