JV10
JV10

Reputation: 35

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

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

Upvotes: 0

Views: 211

Answers (1)

Alex Wayne
Alex Wayne

Reputation: 187272

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

Upvotes: 1

Related Questions