I have an example of a map that looks like this
const Map = new Map().set('123', [ [ 'foo', 'bar' ] ]).set('456', [ [ 'baz', 'qux' ], [ 'quux', 'corge' ] ]);
/*
The structure of the Map is as follows:
Map {
'123' => [ [ 'foo', 'bar' ] ],
'456' => [ [ 'baz', 'qux' ], [ 'quux', 'corge' ] ]
}
*/
If I wanted to delete the array where the first nested element equals 'quux', how would I achieve that in order to obtain the following result?
Map {
'123' => [ [ 'foo', 'bar' ] ],
'456' => [ [ 'baz', 'qux' ] ]
}
I can easily remove the item using the following code:
Map.set('456', (Map.get('456')).filter(array => array[0] !== 'quux'));
However, this method only works because I know which key ('456') contains the element with value 'quux'. I am uncertain of how to programmatically search through the Map, identify the corresponding key, and then remove the item. The keys and values within the Map may vary dynamically, but the structure remains consistent. The search term will remain static, for instance: 'quux', meaning that while the contents of the Map may change, I am essentially conducting a search and removal process.