I am facing an issue with a function that retrieves values from an array, and I wish to dynamically return these values.
const AvailableUserRoles = [
{
label: 'Administrator',
value: 1
},
{
label: 'Count',
value: 2
},
{
label: 'Test',
value: 5
}
]
The function I have takes 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 am looking for a way to make this check using dynamic values for easier addition of new options in the future. It should eliminate the need to constantly reference AvailableUserRoles[].value.