Home > Enterprise >  How to get one object at a time from the array?
How to get one object at a time from the array?

Time:09-16

I created an array and to add the id of each order that I scan by Barcode Scanner.

order.page.ts

console.log('returned data: ', infoPedido.data);

console

Its returning in that way on my console:

returned data:  (2) ['000', '111']
                  0: "000"
                  1: "111"
                  length: 2

payload

I need to make it returns in my console, in that format

orders: [
    {"order":{
        "codpedido":integer}
    }
    {"order":{
        "codpedido":integer}
    }
]

CodePudding user response:

I think you want map(), which returns a new item for every item in an array.

const mappedData = infoPedido.data.map(code => {
  return { order: { codpedido: code } }
})
console.log({ orders: mappedData })
  • Related