Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
Delete Multiple keysets in Maps using Javascript?

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!