Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Arvin iuunhao
Added: Jun 18, 2018 8:33 AM
Views: 8
Tags: js
截断一个字符串
  1. const truncate = (str, num) =>
  2.   str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str;
  3. // truncate('boomerang', 7) -> 'boom...'