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

162
Visualizações
How can i ignore "n\" in javascript

so what i wanna do is, i have some text, and when i click some word, it returns me that word. So let's say ' I have a car ', if i click 'car', i want it to return me 'car'. To do that, i tried this:

const alltext = text.toLowerCase().split(" ");

text is the target text (it would be the 'i have a car').

So now i have an array with each word. To render it i did:

alltext.map((item) => (
          <span> {item}</span>
        )) 

And i passed a click function that returns to me the span inner text. And it's working ok most of times, the problem is if i paste a text with two paragraphs, because that blank line becomes '\n' in the array. So if i have like

The american history.

It begins with...

And i paste it, the array is ['the', 'american', 'history.\n\nit', 'begins', 'with']

Allthough it renders decently, the problem is when i click history, it returns 'history. it'. First of all, is there a better/smarter way to do that? And second, how can i fix this?

Thank you

about 4 years ago · Juan Pablo Isaza
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