data = [{'name':'John'},
{'name':'Smith'},
{'name':'James'}]
如何将上述数组格式化为此
var name = {
"user": {
"name" : [{'name':'John'},
{'name':'Smith'},
{'name':'James'}]
}
}
我尝试了var name ['name'] = data并且不知道如何包装结果。我想用'user'作为结果包装结果。
答案 0 :(得分:0)
您无法在创建对象时指定属性。首先创建对象,然后设置属性:
var name = {};
name.user = { name : data };
或立即创建整个对象:
var name = { user: { name: data } };
答案 1 :(得分:0)
var data = [{'name':'John'},
{'name':'Smith'},
{'name':'James'}]
var name = {
"user": {
"name" : data
}
}