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

187
Vistas
How can I change the style after mapping the array with js?

I would like to change the color to green of the element "tr.amount" if its > 0

I tried with the code below but it gives me this error: Uncaught TypeError: Cannot set properties of undefined (setting 'color')

Thanks in advance!

{userData.transactions.length > 0 &&
   userData.transactions.map((tr) => (
       <tr className="border">
         <td> <span className="history-category">{tr.category}</span></td>
         <td className="amount">{tr.amount > 0 ? tr.amount.style.color = "green" : tr.amount.style.color = "red"}</td>
         <td>{tr.date}</td>
       </tr>
))}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You probably want to use the style property of the td itself. Something in lines of

<td className="amount" style={{ color: tr.amount > 0 ? "green" : "red" }}>
  My Content
</td>
about 4 years ago · Juan Pablo Isaza Denunciar

0

You have tr.amount.style.color instead of tr.style.color.

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