L
L
lexstile2020-04-23 21:59:43
JavaScript
lexstile, 2020-04-23 21:59:43

How to implement substring replacement in string with jsx support?

How to implement similar behavior with jsx support?

const array = ['Тверь', 'тверская', 'Тве', 'Колыма'];
const search = 'тве';
const r = () => {
  const rg = new RegExp(search, 'gi');
  return array.map(item => item.replace(rg, "<b>$&</b>"));
}

That is, each element must not be a string in order to be able to embed it in the DOM.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question