0

So I got this JSON response:

{
    "message": "OK",
    "data": [
        {
            "id": 5,
            "full_name": "John Donovan",
            "username": "j.donovan"
        }
    ]
}

I need to get the "full_name" and "username" values.

What I have done is this (I got a "message" value):

axios.post('http://localhost/user/login', sendData)
        .then((result) => {         
            if (result.data.message === 'OK') {

                console.log(result.data.username});
            }
        })

I successfully get the value of "message" but failed to get the value for "full_name" and "username". The result for console.log above is "undefined".

Tried googling and searching in this forum still have not found the answer. Please your correction.

Thank you.

1 Answer 1

1

data is an array. need to access the index

console.log(result.data.data[0].username})
Sign up to request clarification or add additional context in comments.

1 Comment

Ahhh thank you so much Sachila! Finally, I can get the value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.