I have an array
我有一个阵列
var user=[];
user['name']="joy";
user['age']= "12";
is there any function in node.js .So that i can get the json output like
在node.js中是否有任何函数。所以我可以得到json输出
{"name":"joy","age":"12"}
2 个解决方案
#1
No, there is no predefined function in nodejs that will do it for you. But as said by the others, you can do it manually or avoid the problem by defining the array as an objet.
不,nodejs中没有预定义的功能可以为您完成。但正如其他人所说,你可以手动完成或通过将数组定义为对象来避免问题。
#2
Thank you for your suggestion.And i got the answer that i want.
谢谢你的建议。我得到了我想要的答案。
var user = {};
user.name = "joy";
user.age = "12";
JSON.stringify(user)
#1
No, there is no predefined function in nodejs that will do it for you. But as said by the others, you can do it manually or avoid the problem by defining the array as an objet.
不,nodejs中没有预定义的功能可以为您完成。但正如其他人所说,你可以手动完成或通过将数组定义为对象来避免问题。
#2
Thank you for your suggestion.And i got the answer that i want.
谢谢你的建议。我得到了我想要的答案。
var user = {};
user.name = "joy";
user.age = "12";
JSON.stringify(user)