Skip to content

Instantly share code, notes, and snippets.

@rob-kistner
Last active May 1, 2019 02:41
Show Gist options
  • Select an option

  • Save rob-kistner/c8ec6100bf7b3235f834e21e44aa17b8 to your computer and use it in GitHub Desktop.

Select an option

Save rob-kistner/c8ec6100bf7b3235f834e21e44aa17b8 to your computer and use it in GitHub Desktop.
Find in JSON
const data = [
{ "id": "1", "firstname": "Friendly", "lastname": "Glenn" },
{ "id": "5", "firstname": "Ifits", "lastname": "Friendly" },
{ "id": "24", "firstname": "Mya", "lastname": "Crotch" },
{ "id": "81", "firstname": "Glenn", "lastname": "Tipton" },
{ "id": "23", "firstname": "Friendly", "lastname": "Dude" },
];
/* -----------------------------------------
Object extension:
Filters out json to find a specified value
in any of the key / value pairs
------------------------------------------*/
Object.prototype.valueFind = function(val) {
return this.filter( obj => {
return Object.values(obj).find( item => item == val )
})
}
console.log(data.valueFind('Friendly'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment