var arr = [1,2,3,4,5,6,7,8,4,5,6,]
var arr1 = [];
for(var i =0; i< arr.length; i++){
if (arr.indexOf(arr[i])) == i){
arr1.push(arr[i]);
}
}
alert(arr1);
字符串方法
1.獲取字符串元素括號里面?zhèn)魉饕?/h6>
charAt()
2.獲取字符串的索引,如果字符串里面沒有要查找的則返回-1
indexOf()
3.獲取元素包括開始,不包括結(jié)束
substring(start,end)
4.將字符串的字母轉(zhuǎn)為大寫
toUpperCase()
5.將字符串的字母轉(zhuǎn)為小寫
toLowerCase()
字符串反轉(zhuǎn)
var str = "1213addgdsfdsf";
//spilt()字符串為數(shù)組
//reverse()數(shù)組反轉(zhuǎn)
//join()數(shù)組轉(zhuǎn)成字符串
var str1 = str.splot("").reverse().join("")
alert(str1)
先用spilt方法將字符串轉(zhuǎn)成數(shù)組,然后在用數(shù)組反轉(zhuǎn),最后用join將數(shù)組轉(zhuǎn)成字符串