js如何连接两个字符串

1、+连接

  function  isMerge(s,part1,part2)
                   { 
                    var arr=part1+part2
                    alert(arr);
                    
                   }
                   var a1 = "codewars";
   var a2 = "cdw";
   var a3 = "oears";
   document.write(isMerge(a1,a2,a3));
  • 结果:
    cdwoears
    2、数组对象连接:
  • 格式:
    stringObject.concat(stringX,stringX,…,stringX)
    concat() 方法将把它的所有参数转换成字符串,然后按顺序连接到字符串 stringObject 的尾部,并返回连接后的字符串。请注意,stringObject 本身并没有被更改

  • 结果:
    Hello world!

var parents = [“Jani”, “Tove”];
var brothers = [“Stale”, “Kai Jim”, “Borge”];
var children = [“Cecilie”, “Lone”];
var family = parents.concat(brothers, children);document.write(family);

* 结果:
Jani,Tove,Stale,Kai Jim,Borge,Cecilie,Lone
   

你可能感兴趣的:(JS)