【发布时间】:2021-02-06 15:13:09
【问题描述】:
所以我试图将一个数组推送到一个已经是数组格式的 JSON 文件中。
The code im using to attempt this is:
needle.get("https://bpa.st/raw/VHVQ", function(response, body){
let testlist = require('../testlist.json')
let list = response.body;
let listarray = list.split("\r\n")
for (var i of listarray) {
testlist.push(i);
}
当我的应用程序运行时,它将 testlist.json 显示为:
["1", "2", "this", "is", "an", "example", "for", "stackoverflow"]
现在它似乎工作正常,就像它更新了数组一样,但如果我检查它,它没有,如果我重新启动我的应用程序,它会重置为原始的未编辑版本。
testlist.json looks like this:
["1", "2"]
之后,我试图让它编辑 json 文件看起来像这样:
["1", "2", "this", "is", "an", "example", "for", "stackoverflow"]
【问题讨论】:
标签: node.js arrays json npm node-modules