设定一个函数,函数有2个参数 参数1: 要屏蔽关键词的原始字符串 ‘abcabcabcabc’ 参数2: 要屏蔽的关键词 ‘b’ a ca ca ca c function f2(str1,str2){ arr = str1.split('') // ["a", "ca", "ca", "ca", "c"] for(var
设定一个函数,函数有2个参数
参数1: 要屏蔽关键词的原始字符串 ‘abcabcabcabc’
参数2: 要屏蔽的关键词 ‘b’
acacacac
function f2(str1,str2){
arr = str1.split('') // ["a", "ca", "ca", "ca", "c"]
for(var i in arr){
if(arr[i]===str2){
arr[i]='*';
}
}
res = arr.join('') // a*ca*ca*ca*c
return res
}
str1 = 'abcabcabcabc'
str2 = 'b'
res = f1(str1,str2)
console.log(res)
function f1(str1,str2){
arr = str1.split(str2) // ["a", "ca", "ca", "ca", "c"]
res = arr.join('*') //a*ca*ca*ca*c
return res
}
str1 = 'abcabcabcabc'
str2 = 'b'
res = f1(str1,str2)
console.log(res)