【问题标题】:Using Variable in a path Javascript在路径 Javascript 中使用变量
【发布时间】:2020-05-04 19:30:16
【问题描述】:

const dispatcher = connection.playFile('C:/Users/Discord/Desktop/${myArray[Math.floor(Math.random() * 10)]}');

我需要connection.playFile 函数中的字符串能够从数组中获取值,以便我可以传入文件名。

【问题讨论】:

  • 如果某个答案对您有所帮助,请考虑“接受”它;这会将您的问题标记为已解决,并奖励您和回答者一些声誉 - How does accepting an answer work?

标签: javascript arrays discord


【解决方案1】:

使用反引号 (template literal) 而不是单引号 '

然后您将能够访问${...} 中的变量

const dispatcher = connection.playFile(`C:/Users/Discord/Desktop/${myArray[Math.floor(Math.random() * 10)]})`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-03
    • 2022-01-02
    • 1970-01-01
    • 2019-06-09
    • 2021-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多