假设我有以下这段代码:
var array = [cat,dog,fish];
var string = 'The cat and dog ate the fish.';
我想从一个字符串中清除所有这些值。
var result = string.replace(array,"");
结果将会是:
The and ate the .
目前,replace()
函数只用于替换数组中的一个值。如何让它在字符串中替换所有/多个值?感谢!
假设我有以下这段代码:
var array = [cat,dog,fish];
var string = 'The cat and dog ate the fish.';
var result = string.replace(array,"");
The and ate the .
目前,replace()
函数只用于替换数组中的一个值。如何让它在字符串中替换所有/多个值?
for
еҫӘзҺҜжҲ–each()
е’Ңnew RegExp()
еҗ—пјҹжҸҗзӨәпјҢиҜ•иҜ•зңӢгҖӮ - epascarello