Home >Web Front-end >JS Tutorial >Efficiency issues of javascript string splicing_javascript skills

Efficiency issues of javascript string splicing_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 18:13:341170browse
Copy code The code is as follows:

function xntest(){
var d1=new Date() ;
var str="";
for(var i=0;i<10000;i ){
str ="stext";
}
var d2=new Date() ;
document.write("String concatenation method takes time:" (d2.getTime()- d1.getTime()) "Milliseconds;");
d1=new Date();
var sb=new Array();
for(var i=0;i<10000;i ){
sb.push("stext");
}
var result=sb.toString( );
d2=new Date();
document.write(" Array method takes time: " (d2.getTime()- d1.getTime()) "Milliseconds;");
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn