Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda