score:1

Accepted answer

to use a dynamic field name, you have to use square brackets. so you would use:

cocktaillist.filter((cocktail) => cocktail[field] === value)

the issue you are going to run into is the nested key / value pairs under type as you can't use something like type.value with that notation.

score:0

you can do that with cocktail[field]:

const drinktypehandler = (field, value) => {       
    const selectedtype = cocktaillist.filter((cocktail) => cocktail[field] === value);
    console.log(selectedtype); 
}

score:0

in order to access object property using a variable, you need to use dot notation

const drinktypehandler = (field, value) => {       
    const selectedtype = cocktaillist.filter((cocktail) => cocktail[field] === value);
    console.log(selectedtype); 
}

you can read more about bracket and dot notation here


Related Query

More Query from same tag