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

69
Vistas
loop through list from backend

I have list from backend. I want to loop through all the elements of this list and hide the button if it has no status 6.

response

Returning from the response in the incoming list. It won't always be like this. It can come in 7 elements.

policyInstallmentDtoList: Array(1)
 0:
 amount: 291
 currency: "TRY"
 date: "10-02-2022"
 installmentNumber: 1
 status: "3"

I'm trying to loop through the list here.

useEffect(() => {
 if (paymentInfoData?.policyInstallmentDtoList?.forEach((e) => e['status'] !== '6')) {
   setHiddenControlButtonClass('hidden');
 }
}

html

<div className={hiddenControlButtonClass}>
  <AS.Button variant="outlined" onClick={handlePayment}>
    Devam
  </AS.Button>
</div>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use Array.some

It's a built-in method in JS's array prototype which returns a boolean value that represents whether or not at-least a single member in the array answers your condition.

useEffect(() => {
 if (!paymentInfoData?.policyInstallmentDtoList?.some(e => e.['status'] === '6') {
   setHiddenControlButtonClass('hidden');
 }
}

This should work just fine and only set the state once,
which is better for performance.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You don't need to put the forEach method in an if statement.

useEffect(() => {
  paymentInfoData?.policyInstallmentDtoList?.forEach((e) => {
    if (e.status !== '6') {
      setHiddenControlButtonClass('hidden');
    }
  }
}
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