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的更多相关文章

  1. [Javascript ] Array methods in depth - sort

    Sort can automatically arrange items in an array. In this lesson we look at the basics including how ...

  2. [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 ' ...

  3. [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 ...

  4. [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 ...

  5. [Javascript] Array methods in depth - some

    some returns a boolean value after passing each item in the source array through the test function t ...

  6. JavaScript Array methods performance compare

    JavaScript Array methods performance compare JavaScript数组方法的性能对比 env $ node -v # v12.18.0 push vs un ...

  7. javascript Array Methods(学习笔记)

    ECMAScript 5 定义了9个新的数组方法,分别为: 1.forEach();  2.map();  3.filter();  4.every();  5.some();  6.reduce() ...

  8. JavaScript Array filter() 方法

    JavaScript Array filter() 方法 var ages = [32, 33, 16, 40]; function checkAdult(age) { return age > ...

  9. JavaScript Array -->map()、filter()、reduce()、forEach()函数的使用

    题目: 1.得到 3000 到 3500 之内工资的人. 2.增加一个年龄的字段,并且计算其年龄. 3.打印出每个人的所在城市 4.计算所有人的工资的总和. 测试数据: function getDat ...

随机推荐

  1. Java序列化的机制和原理

    Java序列化的机制和原理 本文讲解了Java序列化的机制和原理.从文中你可以了解如何序列化一个对象,什么时候需要序列化以及Java序列化的算法. 有关Java对象的序列化和反序列化也算是Java基础 ...

  2. get the text value of a selected option.

    <select id="myselect"> <option value="1">Mr</option> <optio ...

  3. Delphi 用ToolButton和MonthCalendar实现DateTimePicker的功能

    效果图如下: 实现平台:xp xe2,其中以上功能的实现,核心主要是参考了万一老师的资料,连接:http://www.cnblogs.com/del/archive/2011/05/12/204411 ...

  4. java学习——IO流

    字符流的由来:其实就是:字节流读取文字字节数据后,不直接操作而是先查指定的编码表.获取对应的文字.在对这个文字进行操作.简单说:字节流+编码表 ---------------------------- ...

  5. python密码处理(可用于生产模式)

    import os from hashlib import sha256 from hmac import HMAC def encrypt_password(password, salt=None) ...

  6. Oracle Pl/SQL编程基础

    Pl/SQL简介 提高应用程序的运行性能, 提供模块化的程序设计, 自定义标示符, 具有过程语言控制结构, 良好的兼容性, 处理运行错误. Pl/SQL语言基础 sql是关系数据库的基本操作语言. s ...

  7. STL容器介绍

    STL的容器可以分为以下几个大类: 一:序列容器, 有vector, list, deque, string. 二 : 关联容器,     有set, multiset, map, mulmap, h ...

  8. Apache下PHP的几种工作方式

    PHP在Apache中一共有三种工作方式:CGI模式.Apache模块DLL.FastCGI模式. 一.CGI模式 PHP 在 Apache 2中的 CGI模式.编辑Apache 配置文件httpd. ...

  9. nterrupt 和 using 在C51中断中的使用

    8051系列MCU的基本结构包括:32个I/O口(4 组8bit 端口):两个16位定时计数器:全双工串行通信:6个中断源(2个外部中断.2个定时/计数器中断.1个串口输入/输出中断),两级中断优先级 ...

  10. 【HDOJ】5155 Harry And Magic Box

    DP.dp[i][j]可以表示i行j列满足要求的组合个数,考虑dp[i-1][k]满足条件,那么第i行的那k列可以为任意排列(2^k),其余的j-k列必须全为1,因此dp[i][j] += dp[i- ...