Fetching a value from an object

How can i fetch the value of coordinates in the following json

  {"type": "Polygon", "coordinates": [[[25.19858648066595, 55.24416840158776], 
  [25.23632476437599, 55.27335083566979], [25.234771979573555, 55.31832611643151], 
  [25.19113062071321, 55.31557953440026], [25.185227741234268, 55.258931280005726], 
  [25.19858648066595, 55.24416840158776]]]
  }

I want the output to be in this format

        [
            [25.210895417024087, 55.27594704635814],
            [25.211128381735225, 55.27594704635814],
            [25.212409679674987, 55.276869726259264],
            [25.21176903239144, 55.27777094848827],
            [25.21033241713102, 55.27669806488231]
        ]

Upvotes: 0

Views: 36

Answers (1)

brk
brk

Reputation: 50291

You can access coordinates which is an array and then use flat

const data = {
  "type": "Polygon",
  "coordinates": [
    [
      [25.19858648066595, 55.24416840158776],
      [25.23632476437599, 55.27335083566979],
      [25.234771979573555, 55.31832611643151],
      [25.19113062071321, 55.31557953440026],
      [25.185227741234268, 55.258931280005726],
      [25.19858648066595, 55.24416840158776]
    ]
  ]
}

const val = data.coordinates.flat();
console.log(val)

Upvotes: 1

Related Questions