gpt4 book ai didi

javascript - 如何对字符串执行 "like"或 "contains"搜索?

转载 作者:行者123 更新时间:2023-11-30 07:46:21 24 4
gpt4 key购买 nike

我可以在 if() 条件中比较数组的特定值吗?

X.:

// 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','mail@mail.com','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%”?

最佳答案

if(arr[i].ocupacao.indexOf('t7') >= 0)
{
// do something
}

关于javascript - 如何对字符串执行 "like"或 "contains"搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5355843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com