📜  截断 javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:09.410000             🧑  作者: Mango

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

}

res = truncateString("A-tisket a-tasket A green and yellow basket", 11);
alert(res)