[Javascript] Array methods in depth - filter
Array filter creates a new array with all elements that pass the test implemented by the provided function. In this lesson we discuss how only a truthy or falsey value is required as the return value to the function, which in turns allows us to be creative in how we perform the filter. We end the lesson by looking at an example showing how chaining multiple array methods together can lead to very nice, declarative code.
const lessons = [
{
title: 'Javascript Arrays in Depth - join',
views: 960,
tags: ['array', 'join']
},
{
title: 'Javascript Arrays in Depth - concat',
views: 1050,
tags: ['array', 'concat']
},
{
title: 'Javascript Arrays in Depth - slice',
views: 2503,
tags: ['array', 'slice']
},
{
title: 'Javascript Functions in Depth - bind',
views: 2500,
tags: ['functions', 'bind']
}
]; const minViews = 1000;
const searchTerm = 'array'; const filtered = lessons
.filter(x => x.tags.indexOf(searchTerm) > -1)
.filter(x => x.views > minViews)
.sort((a, b) => b.views - a.views)
.map(x => ` <li>${x.title}</li>`)
.join('\n'); console.log(`<ul>
${filtered}
</ul>`);
[Javascript] Array methods in depth - filter的更多相关文章
- [Javascript ] Array methods in depth - sort
Sort can automatically arrange items in an array. In this lesson we look at the basics including how ...
- [Javascript] Array methods in depth - slice
Array slice creates a shallow copy of an array. In this lesson we cover, in detail, exactly what a ' ...
- [Javascript] Array methods in depth - indexOf
indexOf is used to search for a value or reference inside of an array. In this lesson we first look ...
- [Javascript] JavaScript Array Methods in Depth - push
Array push is used to add elements to the end of an Array. In this lesson we'll see how the push met ...
- [Javascript] Array methods in depth - some
some returns a boolean value after passing each item in the source array through the test function t ...
- JavaScript Array methods performance compare
JavaScript Array methods performance compare JavaScript数组方法的性能对比 env $ node -v # v12.18.0 push vs un ...
- javascript Array Methods(学习笔记)
ECMAScript 5 定义了9个新的数组方法,分别为: 1.forEach(); 2.map(); 3.filter(); 4.every(); 5.some(); 6.reduce() ...
- JavaScript Array filter() 方法
JavaScript Array filter() 方法 var ages = [32, 33, 16, 40]; function checkAdult(age) { return age > ...
- JavaScript Array -->map()、filter()、reduce()、forEach()函数的使用
题目: 1.得到 3000 到 3500 之内工资的人. 2.增加一个年龄的字段,并且计算其年龄. 3.打印出每个人的所在城市 4.计算所有人的工资的总和. 测试数据: function getDat ...
随机推荐
- shareSDK微博分享出现: 分享失败: 错误描述:Insufficient app permissions! 错误码:10014
这个错误是由于appKey所在账号没有微博高级写入接口权限, 需要申请, 详见: http://www.mamicode.com/info-detail-936938.html
- Hive学习之七《 Sqoop import 从关系数据库抽取到HDFS》
一.什么是sqoop Sqoop是一款开源的工具,主要用于在Hadoop(Hive)与传统的数据库(mysql.postgresql...)间进行数据的传递,可以将一个关系型数据库(例如 :MySQL ...
- android 9Path图片的使用
Android UI设计时,经常会使用图片作为背景,比如给按钮设置背景图片时,图片会默认缩放来适应整个按钮.但是有时这种缩放效果并不是我们所需求的.而我们只是希望缩放图片的特定位置,以此来保证按钮的视 ...
- Neutron/ML2学习
Neutron/ML2 Neutron ML2 模块层2(ml2)插件是一种允许OpenStack网络同时地利用在复杂现实数据中心发现的各种第二层网络技术的框架.目前它与存在的openvswitch. ...
- jQuery 使用 jQuery UI 部件工厂编写带状态的插件(翻译)
首先,我们要创建一个progress bar,它只允许我们简单的设置进度值.正如我们接下来将要看到的,我们需要通过调用 jQuery.widget 及其两个参数来实现这一操作,这两个参数分别是:将要创 ...
- phalcon安装和输出 hello word
1:下载和安装Wampserver2.4-x86.exe 服务器: 2:到phalcon官方网站下载对应的dll文件 phalcon_x86_VC9_php5.4.0_1.2.5 我下的是这个版本 所 ...
- Python3 如何优雅地使用正则表达式(详解一)
注:本文翻译自 Regular Expression HOWTO,小甲鱼童鞋对此做了一些注释和修改. 正则表达式介绍 正则表达式(Regular expressions 也称为 REs,或 regex ...
- MVC视图中Html.DropDownList()辅助方法的使用
我们先在控制器中准备好一个SelectList类型,然后通过ViewBag.List传入视图中.SelectList类型是ASP.NET MVC专门为列表有关的HTML辅助方法提供选项的,例如,Htm ...
- 在动态引用DLL-A中,当参数是个实体,而实体的属性在另一个DLL-B中。。我们需要得到A这个实体并将其赋值,并将赋值的实体传人DLL-A的方法中。
string strPath = HttpContext.Current.Server.MapPath("/开放式DLL"); DirectoryInfo df = new Dir ...
- socket函数
为了执行网络IO,一个进程必须做的第一件事就是调用socket函数,指定期望的通信协议类型 int socket(int family,int type,int protocol); 其中,famil ...