I have a problem, I have a function that returns values from an array, but I wanted to return these values dynamically.
const AvailableUserRoles = [
{
label: 'Administrator',
value: 1
},
{
label: 'Count',
value: 2
},
{
label: 'Test',
value: 5
}
]
This is my function, which receives a parameter, which is a numeric value.
function getValue(item){
if(item == AvailableUserRoles[0].value){
return 'Administrator'
}else if(item == AvailableUserRoles[1].value){
return 'Count'
}else if(item == AvailableUserRoles[3].value){
return 'Test'
}
}
}
I would like to do this check with dynamic values as it would be easier to add new options later. No need to continue using AvailableUserRoles[].value