I'm trying to map a nested array using .map(), so I could display and pinpoint all London underground locations in a map.
this.undergroundGeoJson = [ { 'type': 'FeatureCollection','crs': { 'type': 'name', 'properties': { 'name': 'urn:ogc:def:crs:OGC:1.3:CRS84' } }, 'features': [ { 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [-0.278126, 51.5025] }, 'properties': { 'name': 'Acton Town' } }, { 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [-0.263033174, 51.50883531] }, 'properties': { 'name': 'Acton Central' } }, { 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [-0.262879534, 51.50856013] }, 'properties': { 'name': 'Acton Central' } } } ]
I need the coordinates array elements down in the geometry obj.
this is my code so far…
@computed
get undergroundLatLongs() {
return this.undergroundGeoJson.map((u) =>
[u.features.geometry.coordinates[0],
u.features.geometry.coordinates[1]]);
}
and this is the error log…
Uncaught TypeError: Cannot read property ‘coordinates’ of undefined
any help welcomed.
#javascript #arrays #reactjs