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

151
Views
Converting string which have space in it to numbres

I am making a calculator where user can past numbers with spaces like 20 30 40 60 50

and it will calculate all in total = 200

How I can convert this string "20 30 40 60 50" to Numbers with spaces? Because I'll than replace the space with +

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use split with map for transform string to number then use reduce for sum array like:

const string = '20 30 40 60 50';
const arrayNumbers = string.split(' ').map(el => parseInt(el));
const sum = arrayNumbers.reduce((sumCounter, a) => sumCounter + a, 0);
console.log(arrayNumbers, sum);

Please note: If you plan to use decimals use parseFloat instead of parseInt

Reference:

  • String.prototype.split()
  • Array.prototype.map()
  • Array.prototype.reduce()
about 4 years ago · Juan Pablo Isaza 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!