Last active
September 17, 2018 13:55
-
-
Save mikeumus/e94b57fab07d5c49f20479d34a09b812 to your computer and use it in GitHub Desktop.
Revisions
-
mikeumus revised this gist
Sep 17, 2018 . No changes.There are no files selected for viewing
-
mikeumus created this gist
Sep 17, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ 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?' } }