Categories
JavaScript Answers

How to turn all the keys of an object to lower case with JavaScript?

Spread the love

To turn all the keys of an object to lower case with JavaScript, we use some object methods.

For instance, we write

const newObj = Object.fromEntries(
  Object.entries(obj).map(([k, v]) => [k.toLowerCase(), v])
);

to call Object.entries to return an array of key-valye pair arrays from the obj.

Then we call map with a callback to map the keys to lower case with toLowwerCase and v.

And then we call Object.fromEntries to convert the mapped key-value pair array back to an object.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *