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

254
Visualizações
How to get character After space in javascript

I am working on Avatar component in react where I want to get the first character and character after space and give the result to the avatar and display the abbreviated version of the full name for example:-

var fullName = ahmed hosny;

//I am able to get the first character like this:- 

fullName.charAt(0).toUpperCase() // this prints 'A'

my question is how can I get 'H' from hosny ?? thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use regex for this.

For first occurrence

console.log(fullName.match(/(?<= )./))
// returns [ 'h', index: 6, input: 'ahmed hosny', groups: undefined ]

For all occurrences

console.log(fullName.match(/(?<= )./g))
// returns array of all characters after space
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