且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Javascript中将字符串修剪为N个字符?

更新时间:2023-02-04 23:18:41

为什么不使用子字符串... string.substring(0,7); 第一个参数(0)是起点。第二个参数(7)是结束点(不包括)。 此处提供更多信息。

Why not just use substring... string.substring(0, 7); The first argument (0) is the starting point. The second argument (7) is the ending point (exclusive). More info here.

var string = "this is a string";
var length = 7;
var trimmedString = string.substring(0, length);