【问题标题】:How to loop for an amount of values got from a config.json file如何循环获取从 config.json 文件中获取的大量值
【发布时间】:2020-05-28 10:18:16
【问题描述】:

我将如何获得一个 for 循环来循环 nodejs 中 config.json 文件中的内容量。例如

我想要它做什么:

const auth = require("./tokens.json")
//other code here

for tokens in auth {
        client.login(token)
}

我的 tokens.json 会是这样的

"Tokens": ["xxxxxx",
"xyxyxx",
"asdasdaf",
"etc"]

【问题讨论】:

    标签: javascript node.js json for-loop bots


    【解决方案1】:

    这将迭代存储在“Tokens”键中的元素:

    const auth = require("./tokens.json")
    //other code here
    
    auth["Tokens"].forEach((token) => client.login(token));
    

    【讨论】:

      猜你喜欢
      • 2021-11-04
      • 1970-01-01
      • 2016-10-21
      • 2022-09-25
      • 1970-01-01
      • 2021-11-15
      • 1970-01-01
      • 2021-05-06
      • 1970-01-01
      相关资源
      最近更新 更多