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

214
Vistas
How to Merge Matching key values in Array or Objects

What do I have wrong here? Please feel free to critisise and shame my question formatting, I'm trying to learn how best to ask these questions.

E.g.

{sellerID1: 26.52, sellerID1: 12.46, sellerID2: 72.39}

const cartItems = [{
        "oq23jnq89vj3": {
            sellerID: "aj8f9b73h2v37fy",
            productPrice: 3.99
        }
    },
    {
        "p98nq4hn984t": {
            sellerID: "aj8f9b73h2v37fy",
            productPrice: 19.99
        }
    },
    {
        "vzly89nvhj08": {
            sellerID: "zwlvin3u598n84w",
            productPrice: 10.00
        }
    }
]
for (const item in cartItems) {
    const sellerTotals = {}
    const sellerIDs = {}
    const productPrice = {}
    sellerIDs.push[item.sellerID]
    productPrice.push[item.productPrice]
    const sellerTotals = [...SellerIDs, ...productPrice] where SellerIDs "=="
    SellerIDs
}
console.log(sellerTotals)
// Desired return { sellerID1: 23.98, sellerID2: 10.00}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Thanks to the Reactiflux discord community, this was the solution to my problem of reducing values.

cartItems.reduce((acc, value) => {
        if(acc[value.productSellerUserID]) {
          acc[value.productSellerUserID] += Number(value.productPrice);
        } else {
          acc[value.productSellerUserID] = Number(value.productPrice);
        }
        return acc;
    }, {}),
)
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