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

299
Visualizações
Check in an array ids are equals to dispatch the id value

I create an array of ids value mapping an existing array

const ids = array.map(item => ({ id: item.homologationId }));

This is the result

ids =[{ "id": "15079"},{"id": "15079"},{"id": "15079"},{"id": "15079"},]

From here i want to check if for each item of the ids array the id values are the same ( like in this example ) i want to dispatch in the store the id value (dispatch(setIdValue(value));

How can i do this check?

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

0

You're looking for the .every() Javascript Array method.

Something like this will do the trick.

const ids = array.map(item => ({ id: item.homologationId }));
const [head] = ids
if (head && ids.every(item => item.id == head.id)) {
    dispatch(setIdValue(head.id))
}
about 4 years ago · Juan Pablo Isaza Relatório

0

I would use every function to check the equality of the ids, this function returns true if the all the elements in an iterable fulfills a condition.

const ids =[{ "id": "15079"},{"id": "15079"},{"id": "15079"},{"id": "15079"}]

const element = ids.at(0);
if(ids.every(x => x.id === element.id)) {
  console.log("All the elements are equals")
} else {
  console.log("Not all the elements are equals")
}

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