[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的版本! ...
随机推荐
- C++的表驱动法
目的:使用表驱动法,替换复杂的if/else和switch/case语句. 说明:JS 等其他语言也都支持的. 表驱动发示例:http://blog.csdn.net/zhouyulu/article ...
- Asp.Net中的三种分页方式
Asp.Net中的三种分页方式 通常分页有3种方法,分别是asp.net自带的数据显示空间如GridView等自带的分页,第三方分页控件如aspnetpager,存储过程分页等. 第一种:使用Grid ...
- packinfo-java的作用
package-info.java 包的作用 1. 为标注在包上的Annotation提供便利 2. 声明包的私有类和常量 3. 提供包的整体注释说明 代码说明: package-info.jav ...
- 【POJ】2823 Sliding Window
单调队列. /* 2823 */ #include <iostream> #include <sstream> #include <string> #include ...
- @Resource和@Autowired
@Resource的作用相当于@Autowired,只不过@Autowired按byType自动注入,而@Resource默认按 byName自动注入罢了.@Resource有两个属性是比较重要的,分 ...
- 【CSS3】
Web前端实验室http://demo.doyoe.com/ ::before ::afterCSS3已经将伪元素的前缀更改为双冒号,而伪类则保持为单冒号 backface-visibility ht ...
- 在DDMS中查看网络使用详情
在Android 4.0设置中的“流量使用情况”允许长期统计每个App如何使用网络资源.从4.0.3开始,配合最新发布的DDMS r17(在ADT r17 插件中有集成),您可以实时的在DDMS中查看 ...
- Asm Shader Reference --- Shader Model 2.x part
ps部分 概览 Instruction Set Name Description Instruction slots S ...
- linkscrpit
一 section是什么? 好吧,我们需要解释一下平时编译链接生成的二进制可执行程序(比如说ELF,EXE也行),so或者dll,内核(非压缩的,参加本系列第一节内容.vmlinux),或者ko是怎么 ...
- Apache mod_wsgi部署Django项目
学习python web开发,Django部署备忘 1.下载mod_wsgi,下载路径如下:http://code.google.com/p/modwsgi/downloads/list挑选For 2 ...