Having an array called List that consists of objects with id, name, and grade properties. I'm working on designing a dropdown menu in React where the name is displayed on the left and the corresponding grades are displayed in the dropdown on the right. However, I'm facing an issue where only grades belonging to a specific name should be shown in the dropdown.
const List = [
{id:1, name:"jack", grade:'98'},
{id:2, name:"jack", grade:'96'},
{id:3, name:"jack", grade:'80'},
{id:4, name:"jack", grade:'76'},
{id:5, name:"jack", grade:'78'},
{id:6, name:"marry", grade:'90'},
{id:7, name:"marry", grade:'91'},
{id:8, name:"marry", grade:'96'},
{id:9, name:"marry", grade:'95'},
{id:10, name:"marry", grade:'82'},
{id:11, name:"paul", grade:'87'},
{id:12, name:"paul", grade:'98'},
{id:13, name:"paul", grade:'95'},
{id:14, name:"paul", grade:'93'},
{id:15, name:"paul", grade:'75'},
]
To tackle this problem, I need to create new arrays containing the grades for each individual name. For example, when the name is jack, the grade array should be [98, 96, 80, 76, 78]. Similarly, when the name is marry, the grade array should be [90, 91, 96, 95, 82]. I've attempted using the .map() method but need guidance on how to properly iterate through each name to achieve this behavior.