trim() 删除字符串前后的空格(不包括字符串间的空格)
var str=" hello world ";
console.log(str.trim())//helloworld
toLowerCase() toUpwerCase()
toLowerCase() 转化为小写 toUpwerCase() 转化为大写
var str="helloworld"; var sht="HELLOWORLD"
console.log(sht.toLowerCase())//helloworld
console.log(str.toUpwerCase())//HELLOWORLD
replace()
replace() 可接收2个参数,第一个代表要替换的字符串(或者正则),第二个代表替换的内容
var str="helloworld";
console.log(str.replace("hello","xzz"))//xzzworld
console.log(str.replace(/hello/g,"xzz"))//xzzworld
match()
match() 返回指定的值
var str="helloworld";var str1="1 plus 2 equal 3"
console.log(str.match("hello"))// hello
console.log(str1.match(/\d+/g))// 1,2,3
split()
split()将字符串转化为数组
var str="helloworld";
console.log(str.split("")); //['h','e','l','l','o','w','o','r','l','d'];