str.substring(start,end)//截取下标start到end-1之间的字符串(包含start不包含end)
.end可选,默认从start到结束
.start>end,参数会自动调换位置
.start为负数,等价于start=0
var str='0123456789';
console.log( str.substring(1) );//123456789
console.log( str.substring(1,5));//1234
console.log( str.substring(3,1) );//12
console.log( str.substring(-2));//0123456789
console.log( str.substring(1,-2) );//首先会互换位置(-2,1),等价于(0,1),结果为0
str.substr(start,length)//从指定下标start开始截取length个数
.lenght可选,默认从start到结束
.start为负数,则从后往前截取
var str='0123456789';
console.log( str.substr(1) );//123456789
console.log( str.substr(1,5));//12345
console.log( str.substr(3,1) );//3
console.log( str.substr(-2));//89
str.slice(start,end)//从指定下标start开始截取到指定下标end(包含start不包含end)
.end可选,默认从start截到结束,可为负数
.start需小于end
.start为负数,则从后往前数
var str='0123456789';
console.log( str.slice(1) );//123456789
console.log( str.slice(1,5));/1234
console.log( str.slice(3,1) );//空
console.log( str.slice(-2));//89
console.log( str.slice(1,-2) );//1234567
console.log( str.slice(-5,-2) );//567
str.split(string,limit)//把字符串在string字符(串)处分割,并返回数组
.string可为字符串或正则表达式
.string不填,等价于str转成数组,一个元素
.string=“”,等价于str转成数组,多个元素
.limit可选,返回limit个元素的数组
var str='/http:www/';
console.log( str.split());//["/http:www/"]
console.log( str.split("") );//["/", "h", "t", "t", "p", ":", "w", "w", "w", "/"]
console.log( str.split("/"));//["", "http:www", ""]
console.log( str.split("w"));//["/http:", "", "", "/"]
console.log( str.split("w",1));//["/http:"]