1、方法1
将字符串转换成数组,一个个比过来。
2、方法2
function remove(a, b) {
var _b = b + ',', idx = a.indexOf(b), idx2 = a.indexOf(_b)
if( idx == idx2 )
a = a.replace( _b, '')
return a
}
两种方式可以实现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("")
会得到一个新字符串,将数组中的数组使用空串连接成一个新字符串