I have a code snippet that looks in a Json field called campo
, and inserts it into an array, which can not have repeated values. My array always returned undefined and it took me a while to find the error.
Why does JS and even IDE consider this valid? If campo
is an array, then it is obvious that after .
would call a method. There was no error in the browser.
Wrong code snippet:
while (i < listaContatos.length) {
var dados = listaContatos[i].dados;
for (var j = 0; j < dados.length; j++) {
var nomeCampo = dados[j].campo;
console.log(nomeCampo);
if (campos.indexOf <= -1) {
campos.push(nomeCampo);
}
}
i++;
}