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

335
Views
reduce() method in JavaScript does not work

I having to issues with my code. the first one is that I am trying to format The Total as currency but it does not work. my second issues is I am using the Reduce() method to track and calculate the price when ever the user selects the item till here it works find, but when the user unselects an item it goes back to zero . I do not that I just want to mince it and keep the selected once .

const items = useSelector((state) => state.cartReducers.selectedItems.items);
 
const Total = items
  .map((item) => Number(item.price.replace("$", "")))
  .reduce((prev, curr) => prev + curr, 0);
    
const USD = Total.toLocaleString("en", {
  style: "currency",
  currency: "USD",
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try to change en to en-US

 const USD = Total.toLocaleString('en-US',
  {style: 'currency', currency: 'USD'}
);
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!