网络编程 
首页 > 网络编程 > 浏览文章

JS数组的常见用法实例

(编辑:jimmy 日期: 2026/3/5 浏览:3 次 )

本文实例讲述了JS数组的常见用法。分享给大家供大家参考。具体方法如下:

复制代码 代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>数组方法的应用</title> 
<script type="text/javascript"> 
   var arrayFruit = new Array("apple", "orange", "peach", "bannaner"); 
   document.write("排序前的数组 <br/>"); 
   for(var i in arrayFruit) { 
       document.write(arrayFruit[i] + "<br />"); 
   } 
   arrayFruit.sort();  //对数组进行排序 
   document.write("排序后的数组:<br />"); 
   for(var i in arrayFruit) { 
       document.write(arrayFruit[i] + "<br />"); 
   } 
   document.write("排序后连接的字符串:<br />"); 
   var str = arrayFruit.join("-"); 
   document.write(str); 
    var strFruit = "apple,bannaner,orange,peach"; 
    var tempFruit = strFruit.split(","); 
    document.write("字符串分割成的数组<br />"); 
    for(var i in tempFruit) { 
       document.write(tempFruit[i] + "<br />"); 
   } 
</script> 
</head> 
<body> 
</body> 
</html>

主要介绍数组的遍历和字符串的分割,感兴趣的朋友可以测试运行一下。

希望本文所述对大家的javascript程序设计有所帮助。

上一篇:Node.js抓取中文网页乱码问题和解决方法
下一篇:bootstrap table 服务器端分页例子分享
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。