JS如何去除指定字符串

xiaoxiao2021-02-28  49

1:使用replace函数替换 var str="hello world!"; str=str.replace("l",""); 即使用空串替换某一个字符串,则是可以实现去除指定字符串功能 2:使用字符串分割函数在聚合 var str="hello world!" var items=str.split("o") 会得到一个数组,数组中包括利用o分割后的多个字符串(不包括o) var newStr=items.join(""); 会得到一个新字符串,将数组中的数组使用空串连接成一个新字符串
转载请注明原文地址: https://www.6miu.com/read-79499.html

最新回复(0)