0

I am calling an API that returns

 [{
        Id:string,
        Value:string,
        Value2: 
          [{Id:string,Value3:string}] ,
 {
        Id:string,
        Value:string,
        Value2: 
          [{Id:string,Value3:string}] 
 }]

How do i loop over value 2 with lowest complexity and best approach in JS

1 Answers1

0

I am not sure i understand your issue but you can simply map over your table items like that (assuming a variable called table holds your data):

table.map((item) => {
  console.log(JSON.stringify(item.Value2))
})

And if you want to loop over the values of Value2:

table.map((item) => {
  item.Value2.map((subitem) => {
    console.log(subitem.Value3)
  })
})
godo57
  • 508
  • 2
  • 24