Jim Dover
Jim Dover

Reputation: 623

Wrapping an object inside another object

I have the following 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}
};

I need to wrap this in a parent object, to make the following:

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}
]};

Does anyone know how I could do this?

Upvotes: 0

Views: 851

Answers (1)

panxpiotr
panxpiotr

Reputation: 56

Did you mean

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);

?

Upvotes: 1

Related Questions