1.1 length //获取字符串的长度
var a = "hello world";alert(a.length) //11
1.2增加—连接字符串
concat() 方法用于连接两个或多个字符串。
concat() 方法用于连接两个或多个字符串。
var a = "hello world";
var b = "good";
var c = a.concat(b);
console.log(c);
1.3查询—获取对应字符
charAt(index) //获取在指定下标的字符
charAt(index) //获取在指定下标的字符
var a = "hello world";
alert(a.charAt(0)) //
1.4输入字符返回下标值
indexOf(value) 检索字符串出现的位置,有就返回下标值没有就返回-1
indexOf(value) 检索字符串出现的位置
var a = "hello world";
var b = a.indexOf(“h”); //0;
var c = a.indexOf(“a”); //-1如果没有返回-1 //有就返回下标没有就返回-1
1.5查找字符串
slice(start,end)//输入起始下标值和结束下标值返回之间的数组
stringObject.slice(start,end)//输入起始下标值和结束下标值返回之间的数组元素 生成一个新的字符串
var a = "hello world";
var b = a.slice(0,2);//提取字符串的片段,写在一个新的字符串中
console.log(b); //”he”
1.6同上类似,返回一个新的字符串
stringObject.substr(start,length)同上类似,返回一个新的字符串
var a = "hello world";
var b = a.substr(0,5);//从下标0开始,提取5个数
console.log(b); //hello
1.7n到m之间的字符
提取下标0到2之间的数字
stringObject.substring(start,stop)
var a = "hello world";
var b = a.substring(0,2);提取下标0到2之间的数字
console.log(b); //”he”
1.8字符串分割
字符串分割
split() 方法用于把一个字符串分割成字符串数组。
stringObject.split(separator,howmany)
var a = "hello world";
var b = a.split("");
console.log(b);
1.9 str.search() //返回下标
返回对应下标值
var a = "hello world";
console.log(a.search("h"));//返回对应下标值
1.10 match()返回数组
返回当前值所在的数组
var a ="hello";
console.log(a.match("l"));返回l所在的数组
1.11 replace()替换
(“l”,”“);//把l替换成
var a ="hello";
var b = a.replace("l","*");//把l替换成*
console.log(b);
1.12split将字符串转换为数组
var arr="htmllg"
var arr.split("");
1.13tostring()将数组转换为字符串
var arr=[1,2,3];
console.log(arr.tostring())
