当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javaScript Array(数组)相关方法简述

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 javaScript Array(数组)相关方法简述


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 265 ::
收藏到网摘: n/a

javaScript Array(数组)相关方法简述,让大家更快的熟悉array数组的用法。 1.创建Array对象(赋初值情况下)两种方法:
var aColor=new Array('red','black','yellow');
alert(aColor.toString());//output: red,black,yellow
var aColor=['red','black','blue'];
alert(aColor.toString());//output: red,black,blue
2.length:获取数组长度
3.toString():输出数组中的所有元素。
alert(aColor.toString());////output: red,black,yellow
4.valueOf():同3
5.join():连接数组值,将数组通过连接符连接,返回链接后的字符串
eg.alert(aColor.join("->"));//output:red->black->yellow
//(string)6.split():将字符串分割为字符数组,其中split(" ")将字符串分割为单个字符数组,eg."str"分割为s,t,r
7.contact():将参数附加到数组末尾,返回的函数值是新的Array对象
eg.
var aColor=new Array('red','black','yellow');
var aColorCon=aColor.concat("1","2");
alert(aColorCon.toString());//output: red,black,yellow,1,2
8.slice():返回具有指定项的新数组。
9.push()/pop():push()在数组结尾添加一个项,pop()删除最后一个数组项并将该项值返回。
eg.
var aColor=new Array('red','black','yellow');
aColor.push("blue");
aColor.push("white");
alert(aColor.toString());
aColor.pop();
alert(aColor.toString());
10.shift():删除数组中第一个项
11.unshift():向数组添加第一项,其他的各项后移。
var aColor=new Array('red','black','yellow');
aColor.shift();
alert(aColor.toString());
aColor.unshift("red");
alert(aColor.toString());
12.reverse():颠倒数组项的顺序。
13.sort():对数组项升序排序。
eg.
var aColor=new Array('red','black','yellow');
aColor.sort();
alert(aColor);
alert(aColor.reverse());
14.splice().