数组现有的方法:

.concat():连接两个或更多的数组,并返回结果。

.join():把数组的所有元素放入一个字符串。元素通过指定的分隔符进行分隔。

.pop():删除并返回数组的最后一个元素

.push():向数组的末尾添加一个或更多元素,并返回新的长度。

.reverse():颠倒数组中元素的顺序。

.shift():删除并返回数组的第一个元素

.slice():从某个已有的数组返回选定的元素

.sort():对数组的元素进行排序

.splice():删除元素,并向数组添加新元素。

.toSource():返回该对象的源代码。

.toString():把数组转换为字符串,并返回结果。

.toLocaleString():把数组转换为本地数组,并返回结果。

.unshift():向数组的开头添加一个或更多元素,并返回新的长度。

.valueOf():返回数组对象的原始值

ECMAScript6 为数组新增的方法:

pc;​chrome 45 , Firefox 32 , Edge yes , IE no , opera no , Safari 9.0。

mobile: Android no ,android chrome no,firefox mobile 32.0 , IE moblie no,​opera mobile no,Safari mobile no。

.from(): 从一个类数组对象或iterable(迭代器)对象中创建一个新的数组。

使用方法: Array.from(arrayLike[,mapFn[,thisArg]])

arrayLike :类数组或者迭代器对象​(被转换为数组)

mapfn :可选的,用来访问数组中每一个元素的 MAP function ?(map function 也是JS6的新方法)

thisArg: 可选 Value to use as this when executing mapFn.​ (为map 方法服务的方法)

例:​​

//类数组对象arguments转变为数组

function f() {

return Array.from(arguments);

​}

​f(1, 2, 3);//[1,2,3] ​​

//字符串转变为数组

Array.from("foo"); // ["f", "o", "o"]

//set对象转变为数组 set是JS6新特性

var s = new Set(["foo", window]);

​Array.from(s); // ["foo", window]​

//map 对象转变为数组 map是js6新特性​​​​

var m = new Map([[1, 2], [2, 4], [4, 8]]);

​Array.from(m); // [[1, 2], [2, 4], [4, 8]]

转载:http://blog.sina.com.cn/s/blog_e98696b30102w55n.html

 posted on 2016-01-01 12:29  jayruan  阅读(494)  评论(0编辑  收藏  举报