filtering array of friends javascript code example

Example: filtering array of friends javascript

var namesArray = [
  { name: 'John', friend: 'Steve', brother: 'Jeff', sister: 'Karen' },
  { name: 'Sarah', friend: 'Joan', brother: 'Marvin', sister: 'Diana' },
  { name: 'Morris', friend: 'Tanya', brother: 'Mike', sister: 'Lisa' },
  { name: 'Brian', friend: 'Tim', brother: 'Andrew', sister: 'Tanya' },
];

var tanyaOnly = namesArray.filter(e => Object.values(e).indexOf("Tanya") > -1);

console.log(tanyaOnly);

Tags:

Misc Example