There is a line and it is necessary to find a space after the 100 characters and trim the line. I would be grateful for the help.

2 answers 2

The function String.indexOf has a second parameter, in which you can specify the beginning of the search.

  var res = description.slice(0, description.indexOf(' ', 100)); 
  • Thank! I did not know about the second argument. - Igor Garnik
  cutDescription(description) { if (description.length > 200) { let res = description.slice(0, 200); return description.slice(0, res.lastIndexOf(' ')); } return description; } 

Decided in this way