I have an object
const objectForMapping = {
"001": "Street",
"002": "Name",
"003": "Town"
},
and array with objects
const arrayOfValues = [
{
"questionCode": "002",
"value": "Thomas"
},
{
"questionCode": "001",
"value": "First"
},
{
"questionCode": "003",
"value": "Mexico"
}
],
I want to create table where I need to check if questionCode is present in objectForMapping key and in table I will show an object value connected with the key as label. For example it will look like this
- Name: Thomas
- Street: First
- Town: Mexico
my code I have just correct description not label
{arrayOfValues.map((element, key) => (
<Line label={element.questionCode} description={element.value}
key={key}/>
))}
CodePudding user response:
Instead of
label={element.questionCode}
You want
label={objectForMapping[element.questionCode]}
CodePudding user response:
Do you need something like this?
{arrayOfValues.map((element, key) => (
<Line label={objectForMapping[element.questionCode]} description={element.value}
key={key}/>
))}
CodePudding user response:
{arrayOfValues.map((element, key) => (
<Line label={objectForMapping[element.questionCode]} description={element.value}
key={key}/>
))}