英文:
returning a variable in a span elements it is returning the variable as a string
问题
我有以下的代码,有没有办法在其中使用一个变量?它将变量返回为字符串而不是返回变量的值。
replace = replace.replace(new RegExp(amerMatch[i] + "\\.", "i"), `<span class="highlight">library[amerMatch[i]]</span>` + ".");
结果:
你能把这个放到library[amerMatch[i]]中吗?
英文:
I have the following code is there anyway to use a variable in it? It is returning the variable as a string and not returning the value of the variable.
replace = replace.replace(new RegExp(amerMatch[i] + "\\.", "i"), `<span class="highlight">library[amerMatch[i]]</span>` + ".")
result:
Can you toss this in the library[amerMatch[i]] for me?
答案1
得分: 0
使用${}
`<span class="highlight">library[${amerMatch[i]}]</span>`
英文:
use ${ }
`<span class="highlight">library[${amerMatch[i]}]</span>`
</details>
# 答案2
**得分**: 0
也许你可以使用 `eval(replace)` 来获取库中 `amerMatch[i]` 的结果。
```javascript
replace = replace.replace(new RegExp(amerMatch[i] + ""\\."", "i"), `<span class="highlight">library[amerMatch[i]]</span>` + ".")
var s = eval(replace)
英文:
maybe you can use eval(replace)
to get the result of library[amerMatch[i]]
replace = replace.replace(new RegExp(amerMatch[i] + "\\.", "i"), `<span class="highlight">library[amerMatch[i]]</span>` + ".")
var s = eval(replace)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论