我的列表是词典列表,我想向它添加另一本词典。但是输出将每个字典条目内的列表中的项目显示为[array]。
dict={
"Computer": [{"file" : "MyDirectory/A/text1.txt", "line" :[23,56]},
{"file" :"MyDirectory/B/text5.txt", "line" :[32,91]}]
}
word="Computer"
key='123'
src="MyDirectory/C/text9.txt"
dict[word]=dict[word].concat({"file" : src, "line" : [key]})
console.log(dict)
This is the output
如何使输出看起来像这样:
{ "Computer":
[ { "file":"MyDirectory/A/text1.txt", "line":[23,56]},
{ "file":"MyDirectory/B/text5.txt", "line":[32,91]},
{ "file":"MyDirectory/C/text9.txt", "line":[123]}]}
最佳答案
console.log()只会将您的项目显示到一定深度。如果您只需要一个漂亮的输出,请尝试:
console.log(JSON.stringify(dict, null, 2));