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

338
Vistas
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 Respuestas
Responde la pregunta

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 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