[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 ...
随机推荐
- windows7在局域网中无法映射驱动器问题解决
昨天下班时闲的蛋疼,因电脑比较慢,因此在计算机的[系统配置中]的启动选项下对[启动项目]和[服务]做了误操作,导致在计算机重启之后声卡.显卡.网卡等许多服务禁用,更令人费解的是内网中断了连接,无法访问 ...
- 小试牛刀-嘿嘿,创建job了
今天 周六,我写了这个存储过程.用意:检查 数据库中是否有 该类的 job,如果有那么取job_name 赋值给 job_old, 把job_old加上时间戳 改造成 job_new.那么jo ...
- 利用TOAD实现把EXCEL数据导入oracle数据库
利用TOAD实现把EXCEL数据导入oracle数据库 工具: Toad11.7z(百度搜索,直接下载) 1.将Excel文件中某些字段导入到Oracle数据库的对应表 连接想要导入的数据库 ,然 ...
- OC语法简写
NSNumber [NSNumber numberWithInt:666] 等价于 @666 [NSNumber numberWithLongLong:666ll] 等价于 @666ll [NSNum ...
- NPM环境搭建
1. NPM全局路径:配置npm包的安装位置,在你的用户文件夹下,新建.npmrc文件:cache=D:\NodeJs\nvm\npm-cache 表示缓存文件夹 prefix=D:\NodeJs\n ...
- JDK1.5中LOCK,Condition的使用
import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.uti ...
- 探讨CMake中关于RPATH的使用
最近研究CMake,发现CMake对于RPATH的管理也非常人性化.官方说法是当动态库的编译也和执行档在同级目录下的时候,CMake会自动给执行档加入适当的RPATH.具体可以通过readelf -d ...
- css伪元素
CSS 伪元素用于向某些选择器设置特殊效果. 1.:first-line 伪元素 "first-line" 伪元素用于向文本的首行设置特殊样式.注意:"first-li ...
- 线程间操作无效: 从不是创建控件“textBox2”的线程访问它
如何:对 Windows 窗体控件进行线程安全调用 线程间操作无效: 从不是创建控件的线程访问它的三种方法 如果使用多线程处理来提高 Windows 窗体应用程序的性能,则你必须确保以线程安全的方式调 ...
- process launch failed : failed to get the task for process xxx
原因: 证书问题,project和targets的证书都必须是开发证书,ADHOC的证书会出现此问题. 解决方案: project和targets的证书使用开发证书. 其他: This error ...