Posted at

JavaScript 文字列省略(truncate)ワンライナー

More than 1 year has passed since last update.

function truncate(str, len){

return str.length <= len ? str: (str.substr(0, len)+"...");
}

truncate("1234567890", 5); // "12345..."