array.join()的最重要用法:将数组转化为页面元素。代码如下:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <select id="sel"></select> <script> var sel =document.getElementById("sel"); var array=["拉布拉多","金毛","柯基","比熊"]; var html="<option>" + array.join("</option><option>")+ "</option>"; sel.innerHTML=html; </script> </body> </html>