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

118
Vistas
How can delete the nodes from array objects if array key match

I have array of keys i want to delete the nodes from array of object.

I have tried but not working

if(attr_type === "Blush" || attr_type === "Tie Male"
            || attr_type === "Arm Female Brown"
            || attr_type === "Arm Female Grey"
            || attr_type === "Arm Male Brown"
            || attr_type === "Arm Male Grey"
            || attr_type === "Glasses Or Mask Female"
            || attr_type === "Glasses Or Mask Male"
            || attr_type === "Glasses Or Mask Male For Outfit"
            || attr_type === "Shoes Female"
            || attr_type === "Shoes Male"
            || attr_type === "Boy Shoes"
            || attr_type === "Girl Shoes"
            || attr_type === "Outfit Female Arm Grey"
            || attr_type === "Outfit Female Arm Brown"
            || attr_type === "Pants Female"
            || attr_type === "Pants Male"
        
            ) { 
 
                delete attributes[i];
                  
            }

This is script

[
 'Blush',
 'Tie Male',
 'Arm Female Brown',
 'Outfit Female Arm Grey'
]

This array object

 [
    {
      "trait_type": "Background",
      "value": "Yellow"
    },
    {
      "trait_type": "Blush",
      "value": "None"
    },
    {
      "trait_type": "Body Male Grey",
      "value": "Male Body Grey Color"
    }
    
]

This is final array

[
    {
      "trait_type": "Background",
      "value": "Yellow"
    },
    {
      "trait_type": "Body Male Grey",
      "value": "Male Body Grey Color"
    }
    
]

The array may be many keys and array object has many nodes.

Please help

Thanks

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

i would go this way -

const keyWords = [
        'Blush',
        'Tie Male',
        'Arm Female Brown',
        'Outfit Female Arm Grey'
    ]
    
    const arr = [
        {
            "trait_type": "Background",
            "value": "Yellow"
        },
        {
            "trait_type": "Blush",
            "value": "None"
        },
        {
            "trait_type": "Body Male Grey",
            "value": "Male Body Grey Color"
        }
    
    ]
    
    
    const keyWordsSet = new Set(keyWords);
    
    console.log(arr.filter(obj => !keyWordsSet.has(obj.trait_type)))

about 4 years ago · Juan Pablo Isaza Denunciar

0

How about this?

const array1 = [
 'Blush',
 'Tie Male',
 'Arm Female Brown',
 'Outfit Female Arm Grey'
]

const array2 =  [
  {
    "trait_type": "Background",
    "value": "Yellow"
  },
  {
    "trait_type": "Blush",
    "value": "None"
  },
  {
    "trait_type": "Body Male Grey",
    "value": "Male Body Grey Color"
  }
]

console.log(array2.filter(a2 => !array1.includes(a2.trait_type)))
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can achieve it by using Array.filter() along with Array.includes().

Working Demo :

const blackList = [
 'Blush',
 'Tie Male',
 'Arm Female Brown',
 'Outfit Female Arm Grey'
];

const inputArr = [
    {
      "trait_type": "Background",
      "value": "Yellow"
    },
    {
      "trait_type": "Blush",
      "value": "None"
    },
    {
      "trait_type": "Body Male Grey",
      "value": "Male Body Grey Color"
    }
    
];

const res = inputArr.filter((obj) => !blackList.includes(obj.trait_type));

console.log(res);

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