gpt4 book ai didi

javascript - 数组连接与字符串连接

转载 作者:IT王子 更新时间:2023-10-29 02:53:26 27 4
gpt4 key购买 nike

哪种方法更快?

数组连接:

var str_to_split = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
var myarray = str_to_split.split(",");

var output=myarray.join("");

字符串连接:

var str_to_split = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
var myarray = str_to_split.split(",");

var output = "";
for (var i = 0, len = myarray.length; i<len; i++){
output += myarray[i];
}

最佳答案

字符串连接在 ECMAScript 中更快。这是我为向您展示而创建的基准:

http://jsben.ch/#/OJ3vo

关于javascript - 数组连接与字符串连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7296594/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com