Skip to content

Instantly share code, notes, and snippets.

@javierd79
Created January 7, 2023 00:39
Show Gist options
  • Save javierd79/93a4f9aec7b22e9a269bd6c743419324 to your computer and use it in GitHub Desktop.
Save javierd79/93a4f9aec7b22e9a269bd6c743419324 to your computer and use it in GitHub Desktop.
Array prototype extension to get duplicate objects in an array
interface Array<T> {
has(key: string, value: any): [keyof T, any] | []
}
Array.prototype.has = function(key, value) {
return this.filter((item) => item[key] === value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment