Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda