JavaScript(数组) Array对象创建合并数组

创建数组

  1. <script>
  2. var i;
  3. var mycars = new Array();
  4. mycars[0] = "Saab";
  5. mycars[1] = "Volvo";
  6. mycars[2] = "BMW";
  7. for (i=0;i<mycars.length;i++){
  8. 	document.write(mycars[i] + "<br>");
  9. }
  10. </script>

合并两个数组

  1. <script>
  2. var hege = ["Cecilie", "Lone"];
  3. var stale = ["Emil", "Tobias", "Linus"];
  4. var kai = ["Robin"];
  5. var children = hege.concat(stale,kai);
  6. document.write(children);
  7. </script>

合并三个数组

  1. <script>
  2. var parents = ["Jani", "Tove"];
  3. var brothers = ["Stale", "Kai Jim", "Borge"];
  4. var children = ["Cecilie", "Lone"];
  5. var family = parents.concat(brothers, children);
  6. document.write(family);
  7. </script>

发布日期:

所属分类: JavaScript/jquery 标签:  


没有相关文章!