Object.keys()
and Array.prototype.reduce()
to create a new object from the specified object.String.prototype.toLowerCase()
.const lowercaseKeys = obj => Object.keys(obj).reduce((acc, key) => { acc[key.toLowerCase()] = obj[key]; return acc; }, {});
const myObj = { Name: 'Adam', sUrnAME: 'Smith' };
const myObjLower = lowercaseKeys(myObj); // {name: 'Adam', surname: 'Smith'};
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️