I have the following array of objects:
[
{
"job_id": 1,
"job_name": "Engineer"
},
{
"job_id": 2,
"job_name": "Scientist"
},
{
"job_id": 3,
"job_name": "Teacher"
}
]
where the following code is used to construct a Material-UI Select - options here is the above array of objects:
{options.map(option => {
return (
<MenuItem key={option.job_id} value={option.job_id}>
{option.job_name}
</MenuItem>
)
})}
My questions is, in order to not tie it down to actual key names of option.job_id and option.job_name as I am looking at using different datasets with different key names, but always following this key value pair format - can the map function be changed to make it more generic as to not worry about key names but still return the data for the Select dropdown, i.e.:
{options.map(option => {
return (
<MenuItem key={option.generic_id} value={option.generic_id}>
{option.generic_name}
</MenuItem>
)
})}
I guess I am asking whether it's possible to access the object keys via the map function without needing to know job_id
and job_name
?