将对象包装在另一个对象中

时间:2017-11-10 13:50:38

标签: javascript arrays json object

我有以下对象:

var arr ={
{"id":{"id":"1059","department_id":4476,"location_id":42}},
{"id":"1060","department_id":75,"location_id":42}},
{"id":"178","department_id":75,"location_id":42}
};

我需要将它包装在父对象中,以进行以下操作:

var new_arr = 
 employees: {[
{"id":{"id":"1059","department_id":4476,"location_id":42}},
{"id":"1060","department_id":75,"location_id":42}},
{"id":"178","department_id":75,"location_id":42}
]};

有谁知道我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

你的意思是

var arr =[
{"id":{"id":"1059","department_id":4476,"location_id":42}},
{"id":{"id":"1060","department_id":75,"location_id":42}},
{"id":{"id":"178","department_id":75,"location_id":42}}
];

var employees = {employees:arr};

console.log(employees);