JavaScript 的 字符串replaceAll

等级 3104 次按键

replaceAll()将子字符串的所有出现替换为新字符串。

JavaScript 代码

// 创建一个包含重复单词"foo"的字符串
1const text = "foo bar foo baz foo";
// replaceAll()将每个"foo"替换为"qux"
2const newText = text.replaceAll("foo", "qux");
// 输出“qux bar qux baz qux”
3console.log(newText);

运行结果

qux bar qux baz qux
用这段代码练习打字

可以用这段代码练习打字。成绩不会计入排行榜。

这段代码中的符号

这段 JavaScript 代码中需要输入的符号及其出现次数。

  • "× 6
  • ;× 3
  • .× 2
  • (× 2
  • )× 2
  • =× 2
  • ,× 1

JavaScript 等级 3 的更多代码示例

← 返回 JavaScript 打字练习