Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!