I am trying to fetch a list of Restaurants from the firebase realtime database,
my code snipped for that fetching the data -
_isMounted = false;
state :{
data: [],
}
constructor(props){
super(props)
this.state = {
data:[],
}
}
componentDidMount(){
this._isMounted = true
this.getData()
}
componentWillUnmount(){
this._isMounted = false
}
getData(){
firebase.database().ref('Restaurants/').on("value", snapshot =>{
let restaurantList = snapshot.val();
console.log(restaurantList)
this.setState({data: restaurantList})
});
}
The data structure on Firebase is as follows -

The console output for the array restaurantList is -
Array [
undefined,
Object {
"location": "Testing data",
"name": "Time Traveller",
"rating": 4.5,
"tags": "Indian, Asian",
},
Object {
"locations": "Testing data",
"name": "Novelty",
"rating": 4.5,
"tags": "Indian",
},
]
I am not sure from where I am getting the undefined item in the array.