0

I have a state like this:

        "answers": {
            "1": {
                "name": "....",
                "order": "....",
                "text": "...,
                "type": "..."
            },
            "2": {
                "name": "...",
                "order": "...",
                "text": "....",
                "type": "..."
            },}

I need only names. I tried this.state.answers[0][1] but it doesnt work. how can ı select only names ?

1
  • "answers" should be array not object Commented Nov 2, 2020 at 15:49

1 Answer 1

1

Object.values(answers) will gives you the values of the object as array.

Object.values(ansers).map( a => a.name) just take the names

Maybe learning JS basics, like Object and Array , could be better than skipping to jump into React.

Sign up to request clarification or add additional context in comments.

Comments

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.