JavaScript的数组迭代器函数map和filter,可以遍历数组时产生新的数组,和python的map函数很类似

1> filter是满足条件的留下,是对原数组的过滤;
2> map则是对原数组的加工,映射成一一映射的新数组

 let arr = [1, 2, 3, 4];
let newArr = arr.map(function(item) {  // 使用map方法
return item * 2;
});
console.log(newArr); // [2, 4, 6, 8] let arr = [1, 2, 3, 4];
let newArr = arr.filter(function(item) {  // 使用filter方法
if (item % 2 !== 0) {
return item;
}
});
console.log(newArr); // [1, 3];

最新文章

  1. struts2的action是多例,servlet是单例
  2. 【转】单调队列优化DP
  3. 单据UI代码开发
  4. Codeforces Round #189 (Div. 1) B. Psychos in a Line 单调队列
  5. Oracle EBS-SQL (SYS-23):用户权限查询.sql
  6. [TroubleShootin]The backup set holds a backup of a database other than the existing 'xxdb' database.
  7. 挺好用的SQLSERVER数据库自动备份工具SQLBackupAndFTP(功能全面)
  8. Ubuntu14.04下SP_Flash_Tool_exe_Linux无法烧录
  9. HTML5 进阶系列:canvas 动态图表
  10. 【Xbox one S】开箱&开机&初入坑心得
  11. linux_软件安装策略和升级策略
  12. 《javascript设计模式与开发实践》阅读笔记(15)—— 装饰者模式
  13. mySQL安装与基础配置
  14. Mysql添加字段.md
  15. vuex - 学习日记
  16. nexus 组件下载和上传
  17. 「国庆训练」Bomb(HDU-5934)
  18. 【SQL Server数据迁移】把csv文件中的数据导入SQL Server的方法
  19. Codeforces Round #272 (Div. 1) A. Dreamoon and Sums(数论)
  20. 关于synchronized关键字

热门文章

  1. 南昌网络赛 I. Max answer (单调栈 + 线段树)
  2. Java多线程笔记[未更新完]
  3. header请求头信息详细介绍
  4. HTML5创业的另一种可能
  5. 微服务Kong(四)——添加插件
  6. redis 集群的密码设置
  7. R语言矩阵matrix函数
  8. 决策树遇到sklearn.exceptions.NotFittedError: XXX instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.的解决方案
  9. python模块学习第 0000 题
  10. Unexpected exception 'Cannot run program '的解决