Skip to content

Instantly share code, notes, and snippets.

@cppio
Last active November 19, 2017 18:18
Show Gist options
  • Save cppio/132579c07c3b3c863e2047a6aea23504 to your computer and use it in GitHub Desktop.
Save cppio/132579c07c3b3c863e2047a6aea23504 to your computer and use it in GitHub Desktop.
A function to find a string in an object.
function findString(object, string, seen, path) {
seen = seen || [object];
path = path || "";
for (var i in object) {
try { object[i]; } catch (e) { continue; }
if (!seen.includes(object[i])) {
seen.push(object[i]);
if (object[i] instanceof Object && !(object[i] instanceof HTMLElement))
findString(object[i], string, seen, path + '["' + i + '"]');
else if (typeof object[i] === "string" && object[i].includes(string))
console.log(path + '["' + i + '"]', object[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment