LoginSignup
16
4

More than 5 years have passed since last update.

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

Posted at
function truncate(str, len){
  return str.length <= len ? str: (str.substr(0, len)+"...");
}
truncate("1234567890", 5); // "12345..."
16
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
4