Skip to content

Instantly share code, notes, and snippets.

@andrit
Created September 18, 2018 13:44
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 andrit/f649abfbb31d0abec5769e940aa4bc55 to your computer and use it in GitHub Desktop.
Save andrit/f649abfbb31d0abec5769e940aa4bc55 to your computer and use it in GitHub Desktop.
filter out the object that has a match for the key value
var ob=[
  {name:'john', surname:'miller', role:'teacher'},
  {name:'jill',surname:'smith', role:'student'},
  {name:'jeff', surname:'summers', role:'student'},
  {name:'lisa',surname:'kenson', role:'teacher'}];

let input = 'teacher';

var res = ob.filter(o=>Object.values(o).includes(input));

console.log(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment