var mass = {
"poll" : {
"title" : "Вопрос 1",
"reply" : [
{
"title":"Ответ 1.1",
"type":"radio",
"poll" : {
"title" : "Вопрос 2",
"reply" : [
{
"title" : "Ответ 2.1",
"type" : "radio",
"poll": {
"title" : "Вопрос 3",
"reply" : [
{
"type" : "select",
"items" : []
}
}
]
}
},
{
"title": "Ответ 2.2",
"type":"radio"
}
]
}
},
{
"title": "Ответ 1.2",
"type":"radio"
}
]
}
}
function find(title, poll, parent){
parent = parent || poll;
if (poll.title === title)
return parent;
var result;
poll.reply && poll.reply.some(function(reply){
return reply.poll && (result = find(title, reply.poll, poll)) || false;
});
return result;
}
find('Вопрос 2', mass.poll);