How can I shorten text to a certain length?

In some cases it is necessary that text with a certain character length is shortened. The following code enables exactly this. If the text is longer than 53 characters, it is shortened and a … is added.

jQuery(function($) { 
$(".page-id-1 .title a").text(function(index, currentText) {
  if (currentText.length > 53) {
    return currentText.substr(0, 53)+'...';
  }
});
});