首页 > 其他 > 详细

Array常用方法

时间:2017-09-27 00:16:36      阅读:406      评论:0      收藏:0      [点我收藏+]

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(),实现数组的反转

技术分享

 

Array常用方法

原文:http://www.cnblogs.com/cyany/p/7599651.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!