Hi I have a map consisting of key-value pairs. How do i remove multiple keysets in my map ?
Map creation part
// result key something like 0-119,0-110,0-118 for each entries
this.OptionsMap.set(''+result, selectedList[index]);
Map Deletion Part
Const entriesd = JSON.parse(JSON.stringify(selectedList));
for (let [key, value] of Object.entries(entriesd))
{
if (value.key === 'AB')
{
console.log('keys',value.index)
this.OptionsMap.delete(''+value.index);
}
}
selectedList
(3) [{…}, {…}, {…}]
0: {id: "101", value: "A1B", key: "AB", index: "0-119", …}
1: {id: "130", value: "130", key: "AB", index: "0-110", …}
2: {id: "130", value: "130", key: "AB", index: "0-118", …}
Now in console.log i could get my index like 0-119,0-110,0-118 but in delete part how to remove multiple index? please help me. Thanks in Advance.
What about that?
// SETTING AN EXAMPLE FOR THE CASE
var selected = [
{id: "101", value: "A1B", key: "AA", index: "0-119"},
{id: "130", value: "130", key: "AB", index: "0-110"},
{id: "130", value: "130", key: "AB", index: "0-118"}
];
var optionsMap = new Map([
["0-119", {id: "101", value: "A1B", key: "AA", index: "0-119"}],
["0-110", {id: "130", value: "130", key: "AB", index: "0-110"}],
["0-118", {id: "130", value: "130", key: "AB", index: "0-118"}],
["0-117", {id: "135", value: "131", key: "AB", index: "0-117"}],
["0-116", {id: "136", value: "132", key: "AB", index: "0-116"}],
]);
console.log('optionsMap.size',optionsMap.size);
// ACTUAL FILTERING
// THIS WILL DELETE ONLY THE OPTIONS BEING SPECIFIED IN selected
// AND HAVING KEY 'AB'
selected.filter(item => item.key === 'AB').forEach(el => optionsMap.delete(el.index));
// RESULT
console.log('optionsMap.size',optionsMap.size);