[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 ...
随机推荐
- 运用linq查找所有重复的元素
如题: 有一个List<string>类型的List<T> List<String> list = "};` 需要返回结果List包含 {"6& ...
- 总结Linux下查看流量工具
Linux服务器要查看带宽情况,可以使用nethogs.dstat.nload.iftop.ifstat工具. 而每个工具都有自己的特色,这里简单总结一下使用方法. 一.nethogs 查看这台设备上 ...
- iOS面试小题集锦
1.Object-C有多继承吗?没有的话用什么代替? cocoa 中所有的类都是NSObject 的子类 多继承在这里是用protocol 委托代理 来实现的你不用去考虑繁琐的多继承 ,虚基类的概 ...
- Asp.net 主题
设定主题: 右击网站,选择添加ASP.NET文件夹,选择主题.系统默认将文件夹命名为App_Themes,我们在这个文件夹下添加外观文件,在.skin后缀的文件中自定义我们想要的主题. 例如: < ...
- .net中XML的创建02(linqToXml)
linqToXml比较的灵活和方便,它是基于函数式编程具体的使用如下:引用程序集using System.Xml.Linq; 1.创建XDocument并设置文档头 XDocument XDoc = ...
- 10_RHEL安装搜狗输入法
首先需要安装相关源 1.加入EPEL源 EPEL7几乎是必备的源: $ sudo yum install epel-release 2.添加mosquito-myrepo源 mosquito-myre ...
- js 判断url的?后参数是否包含某个字符串
function GetQueryString(name){ var reg=eval("/"+name+"/g"); var r = window. ...
- PHP之路——PHPStudy虚拟主机
一: Apache/conf/httpd.conf打开以下扩展 LoadModule rewrite_module modules/mod_rewrite.so LoadModule vhost_al ...
- HIVE json格式数据的处理
今天要处理一个以json格式存储的数据,想要直接把json的各个项的数据存入HIVE表中. HIVE直接读入json的函数有两个: (1)get_json_object(string json_str ...
- Zend Cache的学习和实例
前一段时间,公司让我组织一下关于Zend Cache的培训. 培训的具体内容有: 前端core缓存 前端Output缓存 前端Function缓存 前端Class缓存 前端File缓存 前端Page缓 ...