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

114
Views
How to count the total number of letters or characters inside of an array in Javascript

Part of a JavaScript program I am writing asks to count the total number of the letters from the array objects. So for example if I had an array like this.

["apple", "pear"] 

The total count of letters would be 9. I am not sure if their is a char count function in JavaScript and a lot of the examples I have seen on here only count the occurrences of individual letters. Any help with this would be appreciated.

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

0

There are a few ways you could do this, but I think the following is a good one:

var x = ["apple", "pear"];
var result = x.map(a => a.length).reduce((a, b) => a + b);
console.log(result)

This uses the map function to turn x into an array of each item's length, in this case [5, 4]. Then sums that array using the reduce function.

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!