当前位置: 代码迷 >> 综合 >> indexOf() 不区分大小写
  详细解决方案

indexOf() 不区分大小写

热度:94   发布时间:2023-12-17 05:38:23.0

indexOf 不区分大小写

  • indexOf()
  • 代码

indexOf()

indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。如果没有出现,则输出-1。

indexOf() 方法对大小写敏感!所以要检索字符串且忽略大小写的时候,可以先把字符串转换成全部大写,或者全部小写!

代码

var arr=['Kmeans','algo','machineLearning'];
var test_col='kMeans';_.each(arr,function(col){
    if(col.toUpperCase().indexOf(test_col.toUpperCase() != -1)){
    console.log(col);}
})
  相关解决方案