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

216
Visualizações
Delete object from an array if the key value match

Hi I have this object

obj = [
 {id: 145, value: '$ 1.024.100'}
 {id: 146, value: '$ 679.200'}
 {id: 147, value: '$ 679.200'}
]

From a checkbox I'm getting a value and id, I'm trying that if that value and id match remove the array that match

So I'm looking that if the value and id that I send is for example $ 679.200 and 146 the obj result is this

obj = [
 {id: 145, value: '$ 1.024.100'}
 {id: 147, value: '$ 679.200'}
]

I tried this but doesn't work

var index: number = obj.indexOf(ob.source.value, id);
obj.splice(index, 1);

It delete it but not the value and id that match

any help I will appreciate

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Using Array#findIndex:

const removeElemWithIdAndValue = (arr = [], targetId, targetValue) => {
  const index = arr.findIndex(({ id, value }) => id === targetId && value === targetValue);
  if(index >= 0) arr.splice(index, 1);
}

const arr = [ {id: 145, value: '$ 1.024.100'}, {id: 146, value: '$ 679.200'}, {id: 147, value: '$ 679.200'} ];
removeElemWithIdAndValue(arr, 1461, '$ 679.200');
console.log(arr);

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