[Javascript] Chaining the Array map and filter methods
Both map and filter do not modify the array. Instead they return a new array of the results. Because both map and filter return Arrays, we can chain these functions together to build complex array transformations with very little code. Finally we can consume the newly created array using forEach. In this lesson, we will learn how to build nontrivial programs without using any loops at all.
var stocks = [
{ symbol: "XFX", price: 240.22, volume: 23432 },
{ symbol: "TNZ", price: 332.19, volume: 234 },
{ symbol: "JXJ", price: 120.22, volume: 5323 },
]; var filteredStockSymbols =
stocks.
filter(function(stock) {
return stock.price >= 150.00;
}).
map(function(stock) {
return stock.symbol;
}) filteredStockSymbols.forEach(function(symbol) {
console.log(symbol);
})
[Javascript] Chaining the Array map and filter methods的更多相关文章
- JavaScript Array -->map()、filter()、reduce()、forEach()函数的使用
题目: 1.得到 3000 到 3500 之内工资的人. 2.增加一个年龄的字段,并且计算其年龄. 3.打印出每个人的所在城市 4.计算所有人的工资的总和. 测试数据: function getDat ...
- [ES2019] Use JavaScript ES2019 flatMap to Map and Filter an Array
ES2019 introduces the Array.prototype.flatMap method. In this lesson, we'll investigate a common use ...
- JavaScript高阶函数 map reduce filter sort
本文是笔者在看廖雪峰老师JavaScript教程时的个人总结 高阶函数 一个函数就接收另一个函数作为参数,这种函数就称之为高阶函数 1.高阶函数之map: ...
- javascript 集合 Object Array Map Set
//Object //创建 var obj = {} function obj(){} class obj{} //Array api Array属性和方法: for 条件判断: break cont ...
- JavaScript中foreach、map、filter、find、every、some的用法
foreach:只是循环数组中的每一项,没有返回值 如: var arr = [2,3,3,4,5,6]; arr.foreach(function(item,index,array){ dosom ...
- 【原】javascript笔记之Array方法forEach&map&filter&some&every&reduce&reduceRight
做前端有多年了,看过不少技术文章,学了新的技术,但更新迭代快的大前端,庞大的知识库,很多学过就忘记了,特别在项目紧急的条件下,哪怕心中隐隐约约有学过一个方法,但会下意识的使用旧的方法去解决,多年前ES ...
- JavaScript高级编程——Array数组迭代(every()、filter()、foreach()、map()、some(),归并(reduce() 和reduceRight() ))
JavaScript高级编程——Array数组迭代(every().filter().foreach().map().some(),归并(reduce() 和reduceRight() )) < ...
- 如何实现JavaScript的Map和Filter函数?
译者按: 鲁迅曾经说过,学习JavaScript最好方式莫过于敲代码了! 原文: Master Map & Filter, Javascript’s Most Powerful Array F ...
- JavaScript 对象Array,Map,Set使用
for(int i = 0 :i < 3 ;i++ ){ //[重点说三遍] 在说明每个对象的用法之前,首先说明 JavaScript 对象的使用一定要注意浏览器的兼容性问题!尤其是IE的版本! ...
随机推荐
- Linux内核spin_lock与spin_lock_irq分析
http://blog.csdn.net/zhanglei4214/article/details/6837697
- leetcode面试准备: Game of Life
leetcode面试准备: Game of Life 1 题目 According to the Wikipedia's article: "The Game of Life, also k ...
- Python Anaconda2 (64-bit) 安装后启动jupyter-notebook默认目录更改
看了网上很多关于更改 python notebook的,好麻烦,所以想了一招. python notebook 现在改名叫 jupyter-notebook ,被集成在Anaconda中. Anaco ...
- Android开发UI之补间动画-布局添加动画
布局添加动画 使用步骤: 1.获取到布局的id RelativeLayout ly=(RelativeLayout)findViewById(R.id.layout); 2.设置动画样式 ScaleA ...
- NOI2008假面舞会
1064: [Noi2008]假面舞会 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 883 Solved: 462[Submit][Status] ...
- [HDU 1963] Investment
Investment Time Limit:10000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descrip ...
- 虚拟主机apache
1.虚拟主机配置 windows: 1)加载配置虚拟主机的配置文件,在Apache/conf中找到httpd.conf文件,并搜索出以下的两句话,将Include conf/extra/httpd-v ...
- 使用PowerShell脚本部署定时器到MOSS2010
转:http://www.77site.com/tech/1087042010072906074113_2012050808152911.html 第一章 前言 在此次练习中,您将了解到如何使用Pow ...
- SharePoint 2010在win7 x64 安装
转:http://kaneboy.blog.51cto.com/1308893/328000 关于<SharePoint 2010应用程序开发指南>,我和杜伟同学正在撰写中,希望下半年早点 ...
- HDU 4746 Mophues 莫比乌斯反演
分析: http://blog.csdn.net/acdreamers/article/details/12871643 分析参见这一篇 http://wenku.baidu.com/view/fbe ...