Menu

gitpiper

findKeys javascript Code Snippet in 2024

objectbeginner

Last Updated: 20 April 2024

Finds all the keys in the provided object that match the given value.

  • Use Object.keys(obj) to get all the properties of the object.
  • Use Array.prototype.filter() to test each key-value pair and return all keys that are equal to the given value.
const findKeys = (obj, val) => Object.keys(obj).filter(key => obj[key] === val);
const ages = { Leo: 20, Zoey: 21, Jane: 20, }; findKeys(ages, 20); // [ 'Leo', 'Jane' ]

javascript snippet similar to findKeys 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! ✌️