Created
December 1, 2014 10:53
-
-
Save Pmmlabs/93733ccda784e2fe59d5 to your computer and use it in GitHub Desktop.
Поиск по JS объекту
This file contains 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 characters
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