slice(start,end)取子串str = "hello php.cn";
let res = str.slice(0,5);
console.log(res);//hello
res = str.slice(6);
console.log(res);//php.cn
3.substr(start,size)取子串res = str.substr(0,5);
console.log(res);//hello
4.trim():删除字符串两边的空白字符let pw = " 888 ";
console.log(pw.length);//11
console.log(pw.trim());//888
5.split() 将字符串打散成数组res = str.split("");
console.log(res);//["h", "e", "l", "l", "o", " ", "p", "h", "p", ".", "c", "n"]
let email = "demo@mail.com";
res = email.split("@");
console.log(res);//["demo", "mail.com"]
console.log('userName = ',res[0]);//userName = demo
console.log('emailAddress = ',res[1]);//emailAddress = mail.com
6.replace() 替换字符串内容res = email.replace("demo","admin")
console.log(res);// admin@mail.com
数组方法
1.pop() 从数组中删除最后一个元素arr = ["Banana", "Orange", "Apple", "Mango"];
arr.pop();
console.log(arr);// ["Banana", "Orange", "Apple"]
2.push() 在结尾处向数组添加一个新的元素arr.push("Cherry");
console.log(arr);// ["Banana", "Orange", "Apple", "Cherry"]
3.shift() 删除首个数组元素arr.shift();
console.log(arr);// ["Orange", "Apple", "Cherry"]
4.unshift() 将新元素添加到数组的开头arr.unshift("Lemon");
console.log(arr);// ["Lemon", "Orange", "Apple", "Cherry"]