I'm unable to access value's from a state array filled with objects.
I got the values when I stored them in an array, but when I try to console.log the state, it prints out: [Object Object].
I have tried the following to get the value, example:
var data=[{"coordinate":{"longitude":73.8679075241089,"latitude":18.515422222637756},"key":0,"color":"#ffc130"}];
console.log("data"+data[0].coordinate.longitude);
This is how I tried to get the value in React Native:
console.log("location "+JSON.stringify(this.state.markers));
var data=JSON.stringify(this.state.markers);
console.log("datamap"+JSON.parse(data));
var dataparse = JSON.parse(data);
console.log("data parse "+this.state.markers[0].coordinate.latitude);
This is where I declared the array:
class DefaultMarkers extends React.Component {
constructor(props) {
super(props);
this.state = {
region: {
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
},
markers: [],
};
}
I want to store the latitude and longitude in an array.
this.state.markers[0].coordinate.latitudeshould work ifdatain your first snippet corresponds tomarkers. Please create a Minimal, Complete, and Verifiable example in e.g. Snack so that it will be easier for someone to help you.this.state.markers[0].coordinate.latitude@Tholle but i get the error object not found and yes I'll create an example in snack .