1
我可以在if()条件中比较数组的特定值吗?如何在字符串上执行“like”或“contains”搜索?
例:
// teacher object
function Prof(id,tab,nome,ocupacao,email,tel,foto)
{
this.id = id;
this.tab = tab;
this.nome = nome;
this.ocupacao= ocupacao;
this.email = email;
this.tel = tel;
this.foto = foto;
}
//teachers array
var arr = new Array();
arr[0] = new Prof('pf1','dir','Mario','Diretor','[email protected]','tel','foto');
arr[1] = new Prof('pf2','dir','Joao','t1 t3 t7','...','...','...');
...
// So now i will get the array value of "ocupacao" and see if this value has
// an specific value that i´ve defined in the conditional:
...
if(arr[i].ocupacao (has value) t7)
{
//do something
}
注意;有什么我可以在PHP或ASP中使用:“LIKE”或“%value%”?
我改了称呼。这个问题与数组无关。当表达式应用时,'arr [i]'产生一个*值*。假设'x1 = arr [i]'和'x2 = x1.ocupacao',然后观察'x2' *与'arr [i] .ocupacao'具有相同的值*。被查找的东西是对所述*结果值*执行以确定“包含”的操作。请注意'ocupacao'包含一个字符串,而不是一个数组。 – 2011-03-18 17:51:47
除非目标是一次搜索所有'arr [0] ... arr [n]'“? – 2011-03-18 17:56:24