Created
January 14, 2015 18:57
-
-
Save cocodrino/a25dde47e964d82fc376 to your computer and use it in GitHub Desktop.
remove trailing whitespaces from object in javascript (works recursively)
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
var fixKeys = function(obj) { | |
return Object.keys(obj).reduce(function(mem,key) { | |
if(Array.isArray(obj[key])){ | |
mem[key.trim()] = obj[key].map(function(v){return v.trim()}) | |
}else{ | |
if(typeof obj[key] === 'object'){ | |
mem[key.trim()] = fixKeys(obj[key]) | |
}else{ | |
mem[key.trim()] = (obj[key]).trim() | |
} | |
} | |
return mem | |
},{}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment