var str ="4500元"; var num = parseInt(str); console.log(num);//4500
parseInt()方法参数可以有非数字字符串,只要数字在字符串前面就可以
var str ="价格4500元"; var num= s.replace(/[^0-9]/ig,""); alert(num);//4500
功能:使用指定的分隔符,将字符串切割,并且存储到数组里
var str ="a,b,c,d,e,f";
var arr= str.split(",");
console.log(arr);//["a","b","c","d","e","f"]
功能:使用自己指定的分隔符,将一个数组合并成字符串
var arr=[a,b,c,d,e,f]; var str= arr.join("|"); console.log(str);//"a|b|c|d|e|f"
功能:可以截取指定的字段
var str="abcdef"; var str2= str.substring(0,3); console.log(str2);//"abcd"
功能:返回字符串中匹配到子串的第一个字符的下标
var str="hello web"; var s1= str.indexOf("ll");//2
var s2= str.indexOf("j");//如果没有匹配则会返回-1
功能:返回一个从指定位置开始指定长度的字符串
var str="hello web"; var s1= str.substr(0,4);//hell
var s2= str.substr(3);//"lo web"
原文:https://www.cnblogs.com/C-target/p/11288243.html