Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

117
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda