Skip to content

Instantly share code, notes, and snippets.

@muzi131313
Created May 13, 2021 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muzi131313/435292629bce9f9d191d887d941f7d9b to your computer and use it in GitHub Desktop.
Save muzi131313/435292629bce9f9d191d887d941f7d9b to your computer and use it in GitHub Desktop.
function includeKey(objectA, objectB) {
if (!objectA || !objectB) {
return false;
}
const objectAKeys = Object.keys(objectA);
const objectBKeys = Object.keys(objectB);
if (!objectBKeys || !objectBKeys) {
return false;
}
const _include = objectBKeys.some(objectBKey => {
return objectAKeys.includes(objectBKey)
})
return _include;
}
console.log(includeKey({a: 123, b: 33}, {a: 33})); // true
console.log(includeKey({a: 123, b: 33}, {c: 33})); // false
console.log(includeKey({a: 123, b: 33}, {})); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment