Skip to content

Instantly share code, notes, and snippets.

@yairEO
Created February 22, 2020 19:55
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 yairEO/7baecc7aec646cf01fb32a513bcf60da to your computer and use it in GitHub Desktop.
Save yairEO/7baecc7aec646cf01fb32a513bcf60da to your computer and use it in GitHub Desktop.
Check if an Array includes a specific Object
function arrayIncludesObj(arr, obj){
return arr.some(arrObj => JSON.stringify(arrObj) == JSON.stringify(obj))
}
@yairEO
Copy link
Author

yairEO commented Feb 22, 2020

var myArr = [{a:1}, {a:2}, {b:1}];

arrayIncludesObj(myArr, {a:2}) // true
arrayIncludesObj(myArr, {b:2}) // false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment