javascript

Lodash - object keys conversion to lowercase

If you are using lodash library in your project then you can use its transform() function to convert all object keys to lowercase or uppercase format,

let person = {
    "Name": "Richard",
    "Company": "Pied Pieper",
    "Algo Name": "Compression"
};

var result_obj = _.transform(person, function (result, val, key) {
    result[key.toLowerCase()] = val;
});

console.log(result_obj);

Output

{
  "name": "Richard",
  "company": "Pied Pieper",
  "algo name": "Compression"
}

LIVE DEMO

Was this helpful?