2
I would like to search for the word "script" within an object, which would be the variable Roteiro
.
I started trying to figure something out after searching the Internet, but I got lost, and it didn’t work, so I need help with the thinking... as follows:
var Roteiro = {};
var roteiro = [{ descricaoRoteiro: "Descrição roteiro", idRoteiro: 1 }];
var perguntas = [{ tituloPergunta: "Titulo pergunta", idPergunta: 2 }];
var opcoes = [{ tituloOpcao: "Titulo opcao roteiro", idOpcao: 3 }];
Roteiro = { roteiro: roteiro, perguntas: perguntas, opcoes: opcoes};
for (var key in Roteiro) {
debugger;
if(typeof(Roteiro[key]) == "object"){
for (var key2 in Roteiro[key]){
for (var key3 in Roteiro[key][key2]){
for (var name in Roteiro[key][key2][key3].keys){
alert(Roteiro[key][key2][key3]
};
}
}
}
}
After finding some record I would like to pick up the "place" where the word was found, it is possible?
I’m not very good at javascript, but wouldn’t I have an easier way using recursion? something like... Gist Link
– Isvaldo Fernandes
The two answers return the first occurrence found. This is what you need, or you would need to return all?
– bfavaretto