Array常用方法

1.join() 将数组转为字符串

2.pop() 删除数组的最后一个;push()向数组最后添加新元素,返回新数组的长度

3.shift()删除数组的第一个元素;unshift()向数组的最前面插入一个元素,并返回新数组的长度

4.splice() 向数组添加元素

The first parameter (2) defines the position where new elements should be added (spliced in).

The second parameter (0) defines how many elements should be removed.

The rest of the parameters ("Lemon" , "Kiwi") define the new elements to be added.

5.concat() 合并数组,并返回新数组,原数组不变

6.slice() 切割指定字符,并返回新数组

7.sort() 将数组进行排序

数组随机分布:

var points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return 0.5 - Math.random()});

8.reverse(),实现数组的反转

 

posted @ 2017-09-26 23:54  cyany_blue  阅读(127)  评论(0编辑  收藏  举报