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

303
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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