I am trying to add '_x'
to every object key and '_y'
to every object value.
This is the code:
var data = {
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": "GMLXML"
},
"GlossSee": "markup"
}
}
}
}
}
function treee(data) {
Object.keys(data).map( function (key) {
if(Object.keys(data[key]).length == 0){
data[key] = {[key + "_x"]: data[key] + "_y"};
}
else{
data[key] = { [key + "_x"]: treee(data[key]) };
}
});
}
It is not working and I don't know why. Can you please tell what is wrong?