字符串的理解
1. 字符串的属性
str.length
2. 字符串的方法
charAt()
charCodeAt()
indexOf()
lastIndexOf()
slice()
substring()
substr()
includes()
startsWidth()
endsWidh()
toLowerCase()
toUpperCase()
trim()
splite()
1. 字符串的属性
str.length。长度,字符串中字符的个数
2. 字符串的方法:
关注:名称、参数、返回值
2.1 charAt()
理解:根据位置返回指定的字符.
使用:str.charAt(index)
参数:index : 一个介于0和字符串长度减1之间的整数。 (0~length-1),如果没有提供索引,charAt() 将使用0。
返回值:String字符,字符串中对应位置上的字符,没有就是undefined
原字符串:不变
2.2 charCodeAt()
理解:根据位置返回指定的字符在Unicode中的编码。
使用:str.charCodeAt(index)
参数:index : 一个介于0和字符串长度减1之间的整数。 (0~length-1),如果没有提供索引,charCodeAt() 将使用0。
返回值:Number,数字,该字符对应的Unicode编码
原字符串:不变
![]()
let str1 = 'abc';
let res1 = str1.charAt(2);
let res2 = str1.charCodeAt(0);
console.log(res1); //c
console.log(res2); //97
View Code