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

152
Views
Should I use for loops in ReactJS? Any other way to change multiple elements at once when an Input changes?

I'm creating a POS system with ReactJS. Should I use a for loop to calculate the total amount? Is there any other way to do this?

let product = testProducts;
let subtotalEl = document.getElementsByClassName("Subtotal");
let quantity = document.getElementsByClassName("Quantity");
for (var i = 0; i < product.length; i++) {
  subtotalEl[i].innerHTML = product[i].UnitPrice * quantity[i].value;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. You are not using react js, your code looks like JavaScript.
  2. Yes, you can use a loop to add, but in React it is recommended to use map for iterations.

For example:

const sum = array_object
  .map((item) => item.quantity)
  .reduce((prev, curr) => prev + curr, 1);

As you can see, map was used to go through the array, and reduce to add the values.

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!