1.charAt:返回字符串的给定位置的字符串
var arr = 'abcdefg';
console.log(arr.length);//7
console.log(arr.charAt(1));//b
console.log(arr[1]);//b
2.concat:连接2个字符串。原来的不变
var b = arr.concat("abc");
console.log(b);// "abcdefgcde"
3.substring,substr,slice都可省略第二个参数,表示持续到字符串结束。
substring(x,y)返回从x到y(不包括y)
var s = arr.substring(1,3);
console.log(s);// "bc"
substr(x,y)返回从x开始的长度为y的字符串
var s = arr.substr(1,3);
console.log(s);// "bcd"
slice(x,y)返回从x到y(不包括y)位置颠倒时,结果为空字符串
var s = arr.slice(1,3);
console.log(s);// bc
var s = arr.slice(3,1);
console.log(s);// ""
4.trim 去掉两端的空格,不影响之前的字符串
var arr = ' abcdefg ';
var a = arr.trim();
console.log(a);//abcdefg
5.toLowerCase,toUpperCase 转为大小写,原来的不变
var="abcdefg";
var b = arr.toUpperCase();
console.log(b);//"ABCDEFG"
var c = c.toLowerCase();
console.log(c);//"abcdefg"
6.indexOf,lastIndexOf 确定一个字符串在另一个字符串中的第一次出现的位置,一个从头部开始,一个从尾部开始
var arr = 'abccba';
var b = arr.indexOf('b');
console.log(b);// 1
var c = arr.lastIndexOf('c');
console.log(c);// 3
他们还可以接受第二个参数,对于indexOf,表示从该位置向后匹配,对于lastIndexOf,表示从该位置起向前匹配
7.split 切割字符串
var arr = 'a b c c b a';
var b = arr.split(' ');
console.log(b);// ["a", "b", "c", "c", "b", "a"]