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