function recursiveSearch(what, where) { var depth = new Object(); depth.depth = []; function search(what, where, depth) { if (typeof where == 'object') { depth.depth.push(0); for (var i=0; i < where.length; i++) { depth.depth[depth.depth.length - 1] = i; search(what, where[i], depth); } depth.pop(); } else { if (what == where) { throw "Done!"; } } } try { search(what, where, depth); } catch (e) { if (e == "Done!") return depth; } }