Last active
November 6, 2019 17:58
-
-
Save pooyagolchian/eb8d1dff5da3db1647fc2b773beef39a to your computer and use it in GitHub Desktop.
Find in array of object by object (Module)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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