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

78
Views
Adding Using Reduce Function in JavaScript

I have a very simple problem. I wanted to get the total gross using reduce function. My problem is that its a string but I already added + to make it a number. I wonder that output is still NaN?

const hello = [
    {
        "gross": "391.50",
    },
    {
        "gross": "489.80",
    }
]

const final = hello.reduce((prev, cur) => Number(prev.gross) + Number(cur.gross), 0);

console.log(final, 'FINAL')

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

prev is the running total, not an object, there's no prev.gross.

const hello = [{
    "gross": "391.50",
  },
  {
    "gross": "489.80",
  }
]

const final = hello.reduce((prev, cur) => prev + Number(cur.gross), 0);

console.log(final, 'FINAL')

about 4 years ago · Santiago Trujillo 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!