属性
-
:构造函数 。constructor
-
:指向构造函数的原型对象 。__proto__
-
:字符串长度 。length
方法
查找
-
:返回指定位置对应的字符 。carharAt(i)
let a = [1,2,8,4,5,6,0,8] let b = a.toString() let c = b.charAt(2) console.log( c )
-
:返回指定位置字符对应的ASCLL码值 。charCodeAt(i)
let a = [1,2,8,4,5,6,0,8] let b = a.toString() let c = b.charCodeAt(2) console.log( c )
-
:将ASCLL码值转化为字符 。string.fromCharCode(50)
let a = String.fromCharCode(50) console.log(a);
-
:返回指定字符indexOf(str1)
在字符串中首次出现的位置str1
let a = '1,2,8,4,5,6,2,8' let b = a.indexOf('2') console.log(b);
-
:返回指定字符在字符串中最后一次出现的位置,否则返回 -1 。lastIndexOf(str1)
let a = '1,2,8,4,5,6,2,8' let b = a.lastIndexOf('8') console.log(b);
-
:判断字符串中是否包含str1,若包含返回true,否则返回false 。includes(str1)
let a = '1,2,8,4,5,6,2,8' let b = a.includes('9') console.log(b);
替换
-
:用str2替换str1在字符串中首次出现的位置,不影响原字符串 。replace(str1,str2)
let a = '1,2,8,4,5,6,2,8' let b = a.replace(2,9) console.log(b); console.log(a);
重复
-
:字符串重复出现num次 。repeat(num)
let a = '1,2,8,4,5,6,2,8' let b = a.repeat(2) console.log(b); console.log(a);
转换
-
:转换为大写 。str.toUpperCase()
let a = 'a,b,c,d,e,f,8' let b = a.toUpperCase() console.log(b)
-
:转换为小写 。sre.toLowerCase()
let a = 'E,D,C,G,U,I,8' let b = a.toLowerCase() console.log(b)
-
:按照指定的标识符,将字符串转换为数组 。split()
let a = 'E,D,C,G,U,I,8' let b = a.split() console.log(b)
截取
-
:截取从slice(start,end)
到start
,但是不包括end
位置字符,不影响原字符串 。end
let a = 'E,D,C,G,U,I,8' let b = a.slice(1,5) console.log(b) console.log(a)
-
:不支持负数substring(start,end)
let a = 'E,D,C,G,U,I,8' let b = a.substring(1,5) console.log(b) console.log(a)
-
:从substr(start,length)
开始截取指定长度 。start
let a = 'E,D,C,G,U,I,8' let b = a.substr(1,5) console.log(b) console.log(a)