function pullKeys(obj, results, path) { var breadcrumb = path; for (var prop in obj) { if (obj.hasOwnProperty(prop)) { // path = breadcrumb ? breadcrumb ? path : prop : path; // console.log('\n\n path: \n', path, '\n\n'); if (typeof obj[prop] === "object") { path = path ? breadcrumb ? breadcrumb += `.${prop}` : path += `.${prop}` : prop; pullKeys(obj[prop], results, path); } else { var innerObj = {}; innerObj[path] = obj[prop]; results.push(innerObj); } path = breadcrumb ? breadcrumb : path; console.log('\n\n path: \n', path, '\n\n'); } } // console.log('\n\n breadcrumb: \n', breadcrumb, '\n\n'); path = ''; } function deepFind(results, target) { var found = []; results.forEach( function(item) { if ( Object.values(item)[0] === target ) { found.push(item); } }); return found; } function deepSearch(obj, target) { var results = []; pullKeys(obj, results); return deepFind(results, target); } var testObj1 = { notAnObject: 'just a string', iamObject: { now: 'what?' } }