Menu

gitpiper

symbolizeKeys javascript Code Snippet in 2024

objectadvanced

Last Updated: 9 March 2024

Creates a new object, converting each key to a Symbol.

  • Use Object.keys() to get the keys of obj.
  • Use Array.prototype.reduce() and Symbol() to create a new object where each key is converted to a Symbol.
const symbolizeKeys = obj => Object.keys(obj).reduce( (acc, key) => ({ ...acc, [Symbol(key)]: obj[key] }), {} );
symbolizeKeys({ id: 10, name: 'apple' }); // { [Symbol(id)]: 10, [Symbol(name)]: 'apple' }

javascript snippet similar to symbolizeKeys For You in March 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! ✌️