I want to get the last item of a json response.
When i do console.log(this.state.details.sessions) it shows me following json object.
[{"login_time": "12-04-2021 20:52:29", "logout_time": ""}, {"login_time": "12-04-2021 20:54:53", "logout_time": "12-04-2021 20:55:13"}] 
But if try to get the length of this item like:
Object.keys(this.state.details.sessions).length i get this following error:
undefined is not an object (evaluating 'Object.keys(data.sessions)')
const {number} = this.props.route.params;
database().ref('/numbers/'+number.replace('+', ''))
          .on('value', (snapshot) => {
            const userObj = snapshot.val();
            this.setState({
                details: userObj
          })
});
console.log(Object.keys(this.state.details.sessions).length);
What can be the problem?
 
    