I have two arrays: one is a simple array, and the other is an array of objects.
Here are the arrays:-
arr1=["aadhar", "address", "email", "mobile", "name", "pancard", "voterid"];
arr2=[ {
"id": 21,
"name": "johndoe",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="721a171e1e1d32151f131b1b5c111d1b">[email protected]</a>",
"address": "test address",
"voterid": "12131313",
"mobile": "1211313",
"aadhar": "213123131313",
"pancard": "HYG579AA"
},
{
"id": 24,
"name": "johndoe3",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f49c9198989bc5b49399959d98da979b99">[email protected]</a>",
"address": "test address",
"voterid": "12111313",
"mobile": "1211313",
"aadhar": "112313131313",
"pancard": "YHUIHU88"
}];
I am trying to map arr2 within arr1 to retrieve the values using elements from arr1. Here is my attempt:
{arr2.map((item) => {
return (
<Tr key={item.id}>
{arr1.map((itx) => {
return <Td>{item.itx}</Td>;
})}
}
I want the items to be mapped like this:-
item.aadhar
item.address
item.email
item.mobile
and so on...
However, I am unable to use the itx or arr1 after the dot notation, i.e., item.itx (itx is not being utilized).
Please let me know if there is any workaround for this issue.