1. substring(start,end) 返回指定索引区间的字串,不改变原字符串 start 必需,开始位置的索引,一个非负的整数 end 可选,结束位置的索引(不包括其本身),如果未设置,则直接取到字符串的结尾 举个栗子: let str = 'my name is LQW'; console.log(str.substring(2,4)); console.log(str.substring(9));console.log(str); 结果: n s LQWmy name is…
在 JavaScript 中,对于字符串的操作有 substring, substr, slice 等好多个内置函数,这里给大家推荐一篇介绍 substring, substr, slice 三者区别的文章. Extracting a portion of a string is a fairly well understood practice. With JavaScript, there are three different built-in functions which can pe…
substr with different arguments passed in: str.substring(startNum,stopNum ); str.slice(startNum,stopNum ); str.substr(startNum,length ); substring vs slice start = stop ,return ‘ ‘; the same. start or stop bigger than str.length, it will make the big…