[英].replace does nothing when input is a variable
I'm trying to replace a variable globaly in a string, but so far this just returns the same string without modifying it, don't know what I'm doing wrong. 我正在尝试替换字符串中的变量globaly,但是到目前为止,它只是返回相同的字符串而不修改它,不知道我在做什么错。 Can somebody point out what's happening?
有人可以指出发生了什么吗?
var line = "tooth"; var char = line.charAt(0); line.replace(new RegExp(char,"g"), ""); console.log(line);
再次将其分配给变量line
line = line.replace(new RegExp(char,"g"), "");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.