Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda