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

118
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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