1

i have the data like below when i log it in browser console.

const items = getItems(); //this has the logged value
{data: {..}}

data:
    outer:
        first: []
        second: Arrary[2]
            0: {id: '1', name: 'name1'}
            1: {id: '2', name: 'name2'} 

I want the second array of objects so the output should be

second: Array[2]
    0: {id: '1', name: 'name1'}
    1: {id: '2', name: 'name2'}

i have tried below,

const output = data.outer.second 

but says cannot find data.

could someone help me fix this. thanks.

saritha
  • 619
  • 2
  • 12
  • 25

1 Answers1

2

What object you use inside console.log()?. Suppose you are using object items as console.log(items) then you need to get second array like below.

let second = items.data.outer.second;

You can test it below.

const items = {
  data: {
    outer: {
      first: [],
      second: [{
        id: '1',
        name: 'name1'
      }, {
        id: '2',
        name: 'name2'
      }]
    }
  }
}

let second = items.data.outer.second;
console.log(second);
Karan
  • 12,059
  • 3
  • 24
  • 40