I have an array of value pairs as below,
const servingType = [
{value: 'Hot', label: 'Served Hot'},
{value: 'Cold', label: 'Served Cold'},
{value: 'NA', label: 'Not Applicable'}
];
I have an object, which has a dynamic value for serving type. I have to check the serving type in the array and if it matches the value, and display the value in label of the array. My Object :
const selectedItem = {
menuItemID: selectItem.menuItemID || 100,
menuItemName: 'Menu Item Name (M)',
itemPrice: 100
servingType:'Hot',
preparationTime: 15
}
I tried the code as below but I couldn't figure it. Any thoughts on the below code.
<div>
{servingType.map((serveType, id) => (
if(servingType[serveType].value === selectedItem.servingType){
{selectedItem.label}
}
))}
<div>