Skip to content

Instantly share code, notes, and snippets.

@pooyagolchian
Last active November 6, 2019 17:58
Show Gist options
  • Save pooyagolchian/eb8d1dff5da3db1647fc2b773beef39a to your computer and use it in GitHub Desktop.
Save pooyagolchian/eb8d1dff5da3db1647fc2b773beef39a to your computer and use it in GitHub Desktop.
Find in array of object by object (Module)
const findByObject = (arrayOfObject, sourceObject) => {
let arr = [];
const sourceKey = Object.keys(sourceObject);
return collection.filter((obj) => {
return sourceKey
.map((key) => {
return obj.hasOwnProperty(key) && obj[key] === sourceObject[key]
})
.reduce((a,b) => {
return (a && b)
})
})
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment