0

I m using fetch api to call data from the server,the data is received as nested arrays, and i want to display an attribut 'nom' in my console.log but i can t figure out how to do it. my code looks like this:

componentDidMount() {
    
    fetch('*******')
        .then((response) => response.json())
        .then((res) => {
            console.log("!!!test proches")
            console.log(res.proches[0])
            console.log("!!!!!!!!!")
            
        })
        .done();
  }

and this is what i get on my console:

enter image description here

i tried doing console.log(res.proches[0].nom) but i get undefined. I'm new to react native or javascript and i would appreciate your help.

1 Answer 1

1

It looks like when you res.proches[0], that too returns an array. Try pulling the first object from that array out and then use the . notation, like this :

console.log(res.proches[0][0].nom)
Sign up to request clarification or add additional context in comments.

1 Comment

Glad to hear that :)

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.