码迷,mamicode.com
首页 > 其他好文 > 详细

Array常用方法

时间:2017-09-27 00:49:29      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:.so   function   poi   nts   指定   fine   cti   any   slice   

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常用方法

标签:.so   function   poi   nts   指定   fine   cti   any   slice   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!