Search code snippets, questions, articles...

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

Search Index Data (The code snippet can also be found with below search text)

convert al object keys to lowercase using lodash
Was this helpful?
0 Comments