📜  截断字符串 - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:45.293000             🧑  作者: Mango

代码示例3
function truncateString(str, num) {
 
  if (str.length > num) {
    return str.slice(0, num) + "...";
  } else {
    return str;
  }
}

truncateString("Lorem Ipsum placeholder text in any number of characters, words sentences or paragraphs", 9)  // returns Lorem Ips...