[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 ...
随机推荐
- Swift - 13 - 字符串和Character
//: Playground - noun: a place where people can play import UIKit var str = "hi" // 字符串拼接 ...
- JavaScript_object基础
之前写Java时老是有点蒙,大部分都是用jQuery,但原理还不是很清楚,最近一段时间在系统的学习JavaScript,有什么问题或错误请指出,多谢..................... Obje ...
- linux 进程数
一.linux系统支持的最大进程数 限制1:既然系统使用pid_t表示进程号,那么最大进程数不能超过pid_t类型的最大值吧 限制2:使用命令ulimit -u查看系统中限制的最大进程数,我的机器上是 ...
- underscorejs-sortBy学习
2.17 sortBy 2.17.1 语法 _.sortBy(list, iteratee, [context]) 2.17.2 说明 返回一个排序后的list拷贝副本. list为集合,如数组.对象 ...
- js移动设备手机跳转地址代码
if(/AppleWebKit.*mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alc ...
- 关于Python文档读取UTF-8编码文件问题
近来接到一个小项目,读取目标文件中每一行url,并逐个请求url,拿到想要的数据. #-*- coding:utf-8 -*- class IpUrlManager(object): def __in ...
- oracle导入
1 建立all.sql脚本,此脚本内容指定了insert脚本的路径all.sql脚本内容如下: @D:\workspace\workspace-二期开始使用的文件\Test\数据库升级工具\导入基础数 ...
- 转:So Easy!让开发人员更轻松的工具和资源
Cascade Framework 很独特的 CSS 框架,进行了模块化划分,分类排版.表格.颜色.图标和打印样式等等. Mueller Grid System 一个模块化的网格系统,用于响应式或者固 ...
- Color the ball
hdu1556:http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意:中文题. 题解:这一题当然可以直接用线段树来打,但是最近在学树状数组,所以用树状数组 ...
- Jzzhu and Cities
CF #257 div2D:http://codeforces.com/contest/450/problem/D 题意:给你n个城市,m条无向有权边.另外还有k条边,每条边从起到到i.求可以删除这k ...