function titleCase(str) {
//将字符串转化为数组并将其小写化
var arr = str.toLowerCase().split(" ");
for (var i=0;i<arr.length;i++){
var char = arr[i].charAt(0);
arr[i] = arr[i].replace(char, function replace(char){
return char.toUpperCase();
});
}
return arr.join(' ');
//return str;
}
var hehe = titleCase("I'm a little tea pot");
console.log( hehe )
------> I'm A Little Tea Pot
数组字符串去重,虽然很简单,但是经常跟字符串去重、分割之类的弄混淆,记录一下
数组:
var temp=["1","2","1","4","1",]
var Temp = $.unique(temp)
document.write(Temp)
字符串:
//字符串去重
function Str(str){
var newStr=""
for(var i=0;i<str.length;i++){
if(newStr.indexOf(str[i])==-1){
newStr+=str[i]
}
}
return newStr
}
console.log(Str("12345611123789"))
网友评论