My object currently look like this. I'd like to transform the item object into an array of object.
const items = [
{
item_id: 1,
stock_on_hand: 400,
item: {
id: 1,
code: "ITEM 1",
},
},
{
item_id: 2,
stock_on_hand: 150,
item: {
id: 2,
code: "ITEM 2",
},
},
];
This result I want to output:
const items = {
0: {
item_id: 1,
stock_on_hand: 400,
},
1: {
item_id: 2,
stock_on_hand: 150,
},
item: [
{
id: 1,
code: "ITEM 1",
},
{
id: 2,
code: "ITEM 2",
},
],
};
What I've tried:But the item object is still inside the object I want to remove them.
const arr = [];
for(const [key, value] of Object.entries(items)) {
arr.push(Object.assign({}, value.item));
}
const item = {...items, arr};