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.