You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varstr='Twas the night before Xmas...';newstr=str.replace('Twas','Christmas');//"Christmas the night before Xmas..."//或者varstr='Twas the night before Xmas...';newstr=str.replace(/xmas/i,'Christmas');// Twas the night before Christmas...
字符串
split()
mdn
用法:string.split(separator,limit) ,与join相反
例子:
substr()
mdn
方法返回一个字符串中从指定位置开始到指定字符数的字符。
replace()
mdn
返回一个由替换值替换一些或所有匹配的模式后的新字符串。模式可以是一个字符串或者一个正则表达式, 替换值可以是一个字符串或者一个每次匹配都要调用的函数。
用法:str.replace(regexp|substr, newSubStr|function)
先更新到这,更多操作string的api看mdn的string实例
数组
splice和slice的异同点
同:
1.都是返回切割下来的数组
2.初始位置都是从0开始算
异:
1.splice 改变原数组 而slice不会
2.splice三个参数分别是初始位置,删除数量,替换的内容
而slice两个参数分别是初始位置和终点位置
The text was updated successfully, but these errors were encountered: