j.ToShortDescription

PHOTO EMBED

Wed Sep 22 2021 01:30:55 GMT+0000 (Coordinated Universal Time)

Saved by @rick_m #javascript

function ToShortDescription(str, numberOfWords) {
  var words = str.split(' ');
  words.splice(numberOfWords, words.length-1);
  return words.join(' ') + 
    (words.length !== str.split(' ').length ? '&helip;' : '');
}
content_copyCOPY

var sentence = "This is a long sentence!"; console.log(ToShortDescription(sentence, 2));

https://onextrapixel.com/10-useful-and-time-saving-javascript-snippets/