I wrote a small snippet to convert object keys to lowercase. I would like to listen about the ways to improve the following code:
function toLowerCaseKeys(obj) {
return Object.keys(obj).reduce(function(accum, key) {
accum[key.toLowerCase()] = obj[key];
return accum;
}, {});
}
console.clear();
console.log(toLowerCaseKeys({'Foo': true}).foo);
console.log(toLowerCaseKeys({'FoO': true}).foo);
Object.keys().reduce()
vs. just iterating the object properties (i.e.for (key in obj) { ... }
) In other words, if you are worried about performance of this method, have you done anything to test the performance such that you are concerned with your approach? \$\endgroup\$