One common method is to use arr.replace(/xxx/g, "yyy")
. However, a problem arises when the original string is "***"
, as the /* turns the code into a comment. How can I preserve the "***" while still being able to replace it?
Input
let arr = ["***"]
arr.replace(/***/g, "yyy")
Output
let arr = ["yyy"]
This represents the expected outcome.