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

218
Visualizações
How to set each value of the array equal to prevent value - 80 in the following loop only if it's not the first item (JS)

I have an array of objects that contains numeric values. When I loop through it I need to set in the following logic the values in a way that each value starting from second element is equal to the previous value -80

  result.data.forEach((dataItem) => {
        if (dataItem.values && dataItem.values.length) {
          dataItem.sumValue = dataItem.values.reduce((sum, item) => {
            return (sum + item.value)
          }, 0)
        } else dataItem.sumValue = dataItem.value

So each dataItem.sumValue should be equal to the previous value -80.

How can it be achieved?

about 4 years ago · Juan Pablo Isaza
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