Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:35:56 +03:00
parent fc4e61e6fa
commit b3ad01863a
578 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,27 @@
---
title: Find matching keys
type: snippet
tags: [object]
cover: beach-riders
dateModified: 2020-11-15T14:43:44+02:00
---
Finds all the keys in the provided object that match the given value.
- Use `Object.keys()` 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.
```js
const findKeys = (obj, val) =>
Object.keys(obj).filter(key => obj[key] === val);
```
```js
const ages = {
Leo: 20,
Zoey: 21,
Jane: 20,
};
findKeys(ages, 20); // [ 'Leo', 'Jane' ]
```