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

92
Visualizações
how to filter array to only pick last changed value of same id of object in react

This is the function i run on OnChange in AvField

let selectedFieldArray = []

const templateValue = (e) => {
    const fieldObject = {
      "id": e.target.name,
      "value": e.target.value,
    }
    selectedFieldArray.push(fieldObject)
    const uniqueID = selectedFieldArray.filter((obj, id, array) => {
      return id === array.findIndex((t) => (
        t.id === obj.id
      )) 
    })
  }

but in uniqueID it only picks first object of array not the last updated object in array.

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

0

Instead of using arr.findIndex you can use arr.findLastIndex

let selectedFieldArray = [];
const templateValue = (e) => {
  const fieldObject = {
    "id": e.target.name,
    "value": e.target.value,
  }
  selectedFieldArray.push(fieldObject) const uniqueID = selectedFieldArray.filter((obj, id, array) => {
    return id === array.findLastIndex((t) => (t.id === obj.id))
  })
}

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