1.字符串中是否包含某个字符串 indexOf
var Cts = "bblText";
if(Cts.indexOf("Text") >= 0 )
{
alert('Cts中包含Text字符串');
}
2.数组去重
function uniqueArray(a){
temp = new Array();
for(var i = 0; i < a.length; i ++){
if(!contains(temp, a[i])){
temp.length+=1;
temp[temp.length-1] = a[i];
}
}
return temp;
}
function contains(a, e){
for(j=0;j<a.length;j++)if(a[j]==e)return true;
return false;
}
3.数组中是否包含某个值
var arr = [ "xml", "html", "css", "js" ];
$.inArray("js", arr); //返回 3,
如果不包含在数组中,则返回 -1;
var Cts = "bblText";
if(Cts.indexOf("Text") >= 0 )
{
alert('Cts中包含Text字符串');
}
2.数组去重
function uniqueArray(a){
temp = new Array();
for(var i = 0; i < a.length; i ++){
if(!contains(temp, a[i])){
temp.length+=1;
temp[temp.length-1] = a[i];
}
}
return temp;
}
function contains(a, e){
for(j=0;j<a.length;j++)if(a[j]==e)return true;
return false;
}
3.数组中是否包含某个值
var arr = [ "xml", "html", "css", "js" ];
$.inArray("js", arr); //返回 3,
如果不包含在数组中,则返回 -1;