0

I need to get an object inside a mapping by dynamic key, it works with string but not with dynamic name on mapping...

dynamic object

data.map((item) => (

        console.log("** works with string:", props.programStructure["induction"]),

        console.log("** not working with dynamic:", props.programStructure[item.name])
    ))
1
  • props.programStructure[item.name] should work Commented Oct 11, 2021 at 10:08

1 Answer 1

1

Blockquote console.log("** not working with dynamic:", props.programStructure[[item.name]])

I think it is because of the extra [] in props.programStructure[[item.name]]

removed the extra []

var props  = {
  programStructure: {a: 1, b:2, induction: 'intro value'}
}

var data = [{name: 'a'}, {name: 'b'}]


data.map((item) => (

        console.log("** works with string:", props.programStructure["induction"]),

        console.log("** not working with dynamic:", props.programStructure[item.name])
    ))

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

2 Comments

thanks, remoed the []. but not working yet...
can you post an example data what you are iterating ?

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.