如何在 JavaScript 中连接字符串值 length -1。
javascriptweb developmentfront end technologyobject oriented programming更新于 2026/2/14 11:24:17
为此,使用 join()。它将连接字符串值 length-1。
示例
以下是代码 −
var count = 5;
var values = new Array(count + 1).join('John');
console.log(values);
var count1 = 5;
var values1 = new Array(count1).join('John');
console.log(values1);
要运行上述程序,您需要使用以下命令 −
node fileName.js.
这里,文件名是 demo274.js。
输出
这将在控制台上产生以下输出 −
PS C:\Users\Amit\javascript-code> node demo274.js JohnJohnJohnJohnJohn JohnJohnJohnJohn
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

