Skip to content

Instantly share code, notes, and snippets.

@Pmmlabs
Created December 1, 2014 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pmmlabs/93733ccda784e2fe59d5 to your computer and use it in GitHub Desktop.
Save Pmmlabs/93733ccda784e2fe59d5 to your computer and use it in GitHub Desktop.
Поиск по JS объекту
function r(o, max) { // o - родительский объект для поиска, max - максимальный уровень рекурсии.
if (max > 0 && typeof o == 'object' && o != null) {
if (typeof o.cls != 'undefined') // вместо cls пишем свойство, которое хотим найти.
console.log(o);
else
for (i in o)
r(o[i], max - 1);
}
else console.log('end');
}
r(cur, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment