Array常用方法总结
来源:互联网 发布:centos 编译安装lnmp 编辑:程序博客网 时间:2024/04/27 02:42
转换方法
- toLocaleString(): toString(): valueOf():
栈
- push():栈中项插入 pop():栈中项移除
队列
- push():向数组末端添加项 shift():从数组前段取得项
var color =['orange','yellow','green']; color.push('red'); // color.pop(); // color.shift(); // color.reverse(); // color.sort(); // var color2 = color.slice(1,3); //length = 3-1,index = 0,1,2,3->[1,3) var color2 = color.splice(1,2); //length = 3-1,index = 0,1,2,3->[1,3) // alert(color2 ); // console.log(color); // console.log(color2);
重排序方法
- reverse()和sort()方法。
操作方法
- concat()返回一个数组 slice()返回一个数组
splice()
- 删除 插入 替换 返回一个数组
位置方法
- indexOf()和lastIndexOf()
迭代方法
- every():对数组中的每一项运行给定函数,如果该函数对每一项都返回true,则返回true。
some():对数组中的每一项运行给定函数,如果该函数对任一项返回true,则返回true。
filter():对数组中的每一项运行给定函数,返回该函数会返回true的项组成的数组。
forEach():对数组中的每一项运行给定函数。这个方法没有返回值。
map():对数组中的每一项运行给定函数,返回每次函数调用的结果组成的数组
归并方法
- reduce()和reduceRight()//reduce()从前到后,reduceRight()从后到前
var numbers = [1, 2, 3, 4, 5, 4, 3, 2, 1]; var res res= numbers.every(function(item, index, array){ // console.log(item, index, array); return (item >=1); }); // console.log(res); res= numbers.filter(function(item, index, array){ // console.log(item, index, array); return (item > 2); }); // console.log(res); res= numbers.some(function(item, index, array){ // console.log(item, index, array); return (item > 2); }); // console.log(res); res= numbers.map(function(item, index, array){ // console.log(item, index, array); return (item += 2); }); // console.log(numbers); // console.log(res); numbers.forEach(function(item,index, array){ // console.log(item); // console.log(array[index]); // console.log(array); }); var sum = numbers.reduce(function(prev, cur, index, array){ // console.log(prev, cur, index, array); return prev+=cur; }); console.log(sum);
阅读全文
0 0
- Array常用方法总结
- js数组Array对象常用方法总结
- js Array对象的常用方法总结
- 引用类型Array类型的常用方法总结
- js中数组Array的一些常用方法总结
- JavaScript中数组Array.prototype的常用的方法总结
- js中数组Array的一些常用方法总结
- Array类常用方法
- js array 常用方法
- Array对象常用方法
- Array常用方法
- Array的常用方法
- Array对象常用方法
- Array.Copy 方法 总结
- JavaScript Array 方法总结
- JavaScript --Array 对象常用方法
- String、Array常用方法整理
- javascript Array 数组常用方法
- PhpStorm 快捷键大全 PhpStorm 常用快捷键和配置
- C# windows 桌面控件的扩展
- Swagger+NodeJS Mock前端数据
- MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践
- Eclipse自动编译NDK/JNI的三种方法
- Array常用方法总结
- No qualifying bean of type...found for dependency:expected at least 1 bean which qualifies... 异常解决方案
- SPI 串行外设接口
- babel es6转码的基本用法
- iOS 的 c++,c,obj-C,swift 混用 (转载)
- 浅谈区块链开发数字货币过程中环境变量问题
- cocos2d-x IOS11 删除文件 removeFile等修改
- webpack安装及基础配置
- @Autowired注解出错的原因