本文实例讲述了JS数组的常见用法。分享给大家供大家参考。具体方法如下:
代码如下:
"); } arrayFruit.sort(); //对数组进行排序 document.write("排序后的数组:
"); for(var i in arrayFruit) { document.write(arrayFruit[i] + "
"); } document.write("排序后连接的字符串:
"); var str = arrayFruit.join("-"); document.write(str); var strFruit = "apple,bannaner,orange,peach"; var tempFruit = strFruit.split(","); document.write("字符串分割成的数组
"); for(var i in tempFruit) { document.write(tempFruit[i] + "
"); }