If you know exactly the nesting level of your value, a quick solution is possible (as suggested in other answers).
However, if you need a deep crawl search, you will need a recursive version of the solutions, for example:
function FindTraverse(data, match) { for (var prop in data) { if (!data.hasOwnProperty(prop)) continue; if (data[prop] == match) return true; if (typeof data[prop] == 'object' && FindTraverse(data[prop], match)) return true; } return false; }
Examples:
FindTraverse({a:'Foo',b:'Bar'}, 'Bar') // true FindTraverse(['Foo','Bar'], 'Bar') // true FindTraverse([{name:'Foo'},{name:'Bar'}], 'Bar') // true FindTraverse({a:{name:'FooBar'},b:'Bar'}, 'FooBar') // true
However, if you are looking for a more thorough solution, use a framework like jsTraverse
source share