Last active
May 1, 2019 02:41
-
-
Save rob-kistner/c8ec6100bf7b3235f834e21e44aa17b8 to your computer and use it in GitHub Desktop.
Find in JSON
This file contains hidden or 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 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