const _ = require('lodash');
const text = "This is a long text that needs to be truncated.";
// 截断文本,使其不超过 15 个字符,并在末尾添加省略号
const truncatedText = _.truncate(text, { length: 15, omission: '...' });
console.log(truncatedText);
// 输出:This is a lon...
08-27
1855
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-29
1406
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交