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,23 @@
---
title: Common keys
type: snippet
tags: [object]
author: chalarangelo
cover: symmetry-cloudy-mountain
dateModified: 2022-04-23T05:00:00-04:00
---
Finds the common keys between two objects.
- Use `Object.keys()` to get the keys of the first object.
- Use `Object.prototype.hasOwnProperty()` to check if the second object has a key that's in the first object.
- Use `Array.prototype.filter()` to filter out keys that aren't in both objects.
```js
const commonKeys = (obj1, obj2) =>
Object.keys(obj1).filter(key => obj2.hasOwnProperty(key));
```
```js
commonKeys({ a: 1, b: 2 }, { a: 2, c: 1 }); // ['a']
```