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

147
Vistas
How do I extract a certain portion of a string and make it clickable in Javascript?

I have a JS string of this form:

const pageContent = "He stood up and asked the teacher, "Can you elaborate the last point please? ".

I want to map the words to a page and represent it in a view such that the words are clickable. Is there a way to be extract portions of the string using the word index such that any punctuation marks occuring before and after any words are not clickable but the words are? For instance the word Can is clickable but not "Can?

PS: I cannot use the split function to convert the string into an array and map it as this can lead to failure in some edge cases and alters the text flow when converted back into a string. I have the indexes of all the words in a separate array with the starting and end index of each word in the string and want to use these.

Any help is highly appreciated

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Simple use two for loops and check if the word matches any of the words in the excluded words array

const pageContent = 'He stood up and asked the teacher, "Can you elaborate the last point please?", Can you elaborate the last point please? '
const indexes = [
  [35, 39],
  [9, 11]
]
const excluded_words = ['"Can']
for (let i = 0, len = indexes.length; i < len; i++) {
  const word = pageContent.substring(indexes[i][0], indexes[i][1]);

  for (let i = 0, len = excluded_words.length; i < len; i++) {
    if (word.indexOf(excluded_words[i]) > -1) {
      console.log(word, " is excluded");
      break;
    }
    if (i === len - 1) {
      console.log(word, " is included")
    }
  }
}

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