Menu

gitpiper

lowercaseKeys javascript Code Snippet in 2024

objectintermediate

Last Updated: 20 April 2024

Creates a new object from the specified object, where all the keys are in lowercase.

  • Use Object.keys() and Array.prototype.reduce() to create a new object from the specified object.
  • Convert each key in the original object to lowercase, using 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'};

javascript snippet similar to lowercaseKeys For You in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️