当前位置: 首页 > 图文教程 > 网络编程 > Javascript > Prototype使用指南之array.js

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 中的 Prototype使用指南之array.js


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

$A = Array.from(iterable): 将iterable转化为数组,如果iterable定义了toArray方法,就调用这个方法,否则利用iterable的length属性进行枚举, 如果iterable没有length属性的话就返回空数组[]
Array对象除了扩展Enumerable对象的方法外,另外扩展了如下的几个方法,
注意以下方法除了clear外都不改变原来数组,而是返回一个新数组:
clear(): 清除数组,利用arr.length=0
first(): 返回第一个元素
last():返回最后一个元素
compact(): 去除数组中值为null或undefined的元素
flatten(): 将数组扁平化,例如[3,4,[6,7]]变为[3,4,6,7]
without():
去除指定的元素, 可以指定多个值, 例如[4,56,7,8].without(4,7) 返回[56,8]
indexOf(object): 返回指定的元素在数组中的索引,不包含则返回-1
reverse(inline):Array内置函数reverse的增强,当inline为true时,跟内置的reverse函数效果一样,改变原数组的值,否则不改变原来的值
reduce(): 如果数组只有一个元素,则返回这个元素,否则返回数组本身
uniq(): 返回没有重复元素的数组
clone(): 返回一个跟数组相同的数组,Array中的toArray方法覆盖了Enumerable中的toArray方法,指向了这个方法
inspect(): 跟数组的toString方法类似,返回对象的字符串表示,例如[2,3].inspect() 返回 "[2,3]"