I am not sure if I titled it right or not. But I am facing a problem like this
I have an array named folders
[
{
"_id": "62faf0c424411076eb9b80e7",
"name": "My Notes",
"notes": []
},
{
"_id": "62faf0c424411076eb9b80e8",
"name": "Todos",
"notes": []
},
{
"_id": "62faf0c424411076eb9b80e9",
"name": "Projects",
"notes": []
},
{
"_id": "62faf0c424411076eb9b80ea",
"name": "Journals",
"notes": []
},
{
"_id": "62faf0c424411076eb9b80eb",
"name": "Reading list",
"notes": []
}
]
I want to generate an Object from this named FILTER_MAP. It should look like this
{
All: () => true,
'My Notes': (note) => note.folder === 'My Notes',
Todos: (note) => note.folder === 'Todos',
Projects: (note) => note.folder === 'Projects',
Journals: (note) => note.folder === 'Journals',
'Reading list': (note) => note.folder === 'Reading list',
}
I tried .map() method
const FILTER_MAP = folders?.map((folder) => (FILTER_MAP[folder.name] = (note) => note.folder === folder.name));
but it returned something like this
{
All: () => true,
'My Notes': (note) => note.folder === folder.name,
Todos: (note) => note.folder === folder.name,
Projects: (note) => note.folder === folder.name,
Journals: (note) => note.folder === folder.name,
'Reading list': (note) => note.folder === folder.name,
}
How can I get the expected output?