Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!