首页 > 解决方案 > 如何循环获取从 config.json 文件中获取的大量值

问题描述

我将如何获得一个 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"]

标签: javascriptnode.jsjsonfor-loopbots

解决方案


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

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

auth["Tokens"].forEach((token) => client.login(token));

推荐阅读