So i have the following JSON object:
var myObj = {
Name: "Paul",
Address: "27 Light Avenue"
}
and I want to convert its keys to lowercase such that i would get:
var newObj = {
name: "Paul",
address: "27 Light Avenue"
}
I tried the following:
var newObj = mapLower(myObj, function(field) {
return field.toLowerCase();
})
function mapLower(obj, mapFunc) {
return Object.keys(obj).reduce(function(result,key) {
result[key] = mapFunc(obj[key])
return result;
}, {})
}
But I'm getting an error saying "Uncaught TypeError: field.toLowerCase is not a function".