Write in front
Interview process, it is possible to interview to C # that way splicing strings more efficient, and then will be extended to JS in the stitching method. This is also I encountered in the interview problem, at that time, also really did not compare JS in the end which way more efficient. Then, as with speculation, the way you use arrays is then implemented using the Join method.
Code testing
1<! DOCTYPE html>234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>5<title> String Stitching </title>6<script type= "Text/javascript" >7 varStart =NewDate ();8 varstr = "";9 for(vari = 0; i < 1000000; i++) {Tenstr + = "Test"; One } A varEnd =NewDate (); -Document.writeln ("+ stitching strings, time consuming:" + (End.getmilliseconds ()-start.getmilliseconds ())); -Document.writeln ("<br/>"); the varBegin =NewDate (); - varArry =NewArray (); - for(vari = 0; i < 1000000; i++) { -Arry.push ("Test"); + } -Arry.join (""); + varStop =NewDate (); ADocument.writeln ("array-style concatenation of strings, time-consuming:" + (Stop.getmilliseconds ()-begin.getmilliseconds ())); at</script> - -<body> -</body> -Test results
IE11
+ Stitching Strings, Time: 39
Array-style concatenation of strings, time: 31
IE11 Compatibility View
+ Stitching strings, Time: 40
Array-style concatenation of strings, time: 33
IE10
+ Stitching Strings, Time: 39
Array-style concatenation of strings, time: 32
IE9
+ Stitching Strings, Time: 36
Array-style concatenation of strings, time: 33
IE8
+ Stitching strings, Time: 35
Array-style concatenation of strings, time: 35
IE7
+ Stitching Strings, Time: 37
Array-style concatenation of strings, time: 35
SummarizeA knowledge point encountered during an interview is recorded here.
Efficient concatenation of strings in JS