例如:
let jsonArr = { "one", "two", "three" }
我可以使用JavaScript进行修改以使其{ "body": [ "one", "two", "three" ], "error": null }
答案 0 :(得分:2)
好吧,考虑到有错字,不是let jsonArr = { "one", "two", "three" }
,而是 let jsonArr = [ "one", "two", "three" ]
,可以-为什么?
let jsonArr = [ "one", "two", "three" ]
jsonArr = { body: jsonArr, error: null }
答案 1 :(得分:1)
您的问题应包括您尝试过的事情。
您只需要构建新对象。
例如
let jsonArr = [ "one", "two", "three" ]
const jsonObj = Object.assign({}, {
body: jsonArr,
error: null,
});