JSFiddle - React, Tailwind, and code Playground
JavaScript
function ContainsKeyValue( obj, key, value ){
if( obj[key] === value ) return true;
for( all in obj )
{
if( obj[all] != null && obj[all][key] === value ){
return true;
}
if( typeof obj[all] == "object" && obj[all]!= null ){
var found = ContainsKeyValue( obj[all], key, value );
if( found == true ) return true;
}
}
return false;
}
var friends = [{name:'John', phone:'555-1276'},
{name:'Mary', phone:'800-BIG-MARY'},
{name:'Mike', phone:'555-4321'},
{name:'Adam', phone:'555-5678'},
{name:'Julie', phone:'555-8765'}];
var filteredFriends = [];
for( var friend in friends )
{
if( ContainsKeyValue( friends[friend], "name", "John" ) === true )
{
filteredFriends.push( friends[friend] );
}
}
console.log(filteredFriends);