Array.prototype.filter()
1. filter() 方法:创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素
——filter() 不会对空数组进行检测
——filter() 不会改变原始数组
2. 语法:
array.filter(function(currentValue,index,arr), thisValue)
——function(currentValue, index,arr):必须。函数,数组中的每个元素都会执行这个函数
>>currentValue:必须。当前元素的值
>>index:可选。当前元素的索引值
>>arr:可选。当前元素属于的数组对象
——thisValue:可选。对象作为该执行回调时使用,传递给函数,用作 "this" 的值。如果省略了 thisValue ,"this" 的值为 "undefined"
3. 例子:
var ages = [32, 33, 16, 40];
var result = ages.filter(function (age) {
return age >= 18;
});
console.log(result); // [32, 33, 40]
参考资料1:【https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter】
参考资料2:【http://www.runoob.com/jsref/jsref-filter.html】
Array.prototype.filter()的更多相关文章
- Array.prototype.filter()的实现
来源 今年某前端笔试的一道题,大概就是实现一遍filter,包括一个可以改变上下文的要求,其实就是改变this啦,跟原生的filter一样的功能跟参数. 解析 filter的功能就是过滤,传入一个函数 ...
- JavaScript的Array.prototype.filter()详解
摘抄与:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/filter 概述 ...
- Array.prototype.filter(Boolean)
ES5 中的数组有这个方法:Array.prototype.filter ,具体使用参考MDN,这里讲一个特殊应用: 回顾下语法: new_array = arr.filter(callback[, ...
- 数组的方法之(Array.prototype.filter() 方法)
filter() 方法创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素. 注意: filter() 不会对空数组进行检测. 注意: filter() 不会改变原始 ...
- javascript替代Array.prototype.some操作
Array.prototype.some在低版本浏览器好像不太兼容,下列是替代方法 一. for 循环 const initIds: any[] = [1,2,3]; const Ids: any[] ...
- 数组方法 Array.prototype
Object.prototype 数组的值是有序的集合,每一个值叫做元素,每一个元素在数组中都有数字位置编号,也就是索引,js中数组是弱类型的,数组中可以含有不同类型的元素.数组元素甚至可以是对象或者 ...
- 来自数组原型 Array.prototype 的遍历函数
1. Array.prototype.forEach() forEach() 是一个专为遍历数组而生的方法,它没有返回值,也不会改变原数组,只是简单粗暴的将数组遍历一次 参数: callback() ...
- Array.prototype
Array.prototype 属性表示 Array 构造函数的原型,并允许您向所有Array对象添加新的属性和方法. /* 如果JavaScript本身不提供 first() 方法, 添加一个返回 ...
- Array.prototype.map()和Array.prototypefilter()
ES5 => 筛选功能 Array.prototypefilter(): 代码: var words = ['spray', 'limit', 'elite', 'exuberant', 'd ...
随机推荐
- js 获取json对象的 键 和 值
直接上图 结果:
- 在Google Maps 上点击标签后显示说明
JS如下: (function() { window.onload = function() { // Creating an object literal contain ...
- DNS服务基础
DNS服务器的功能 – 正向解析:根据注册的域名查找其对应的IP地址 – 反向解析:根据IP地址查找对应的注册域名(不常用) NS(声明DNS记录) A(正向解析记录) CNAME(解析记录别名) 安 ...
- fatal: refusing to merge unrelated histories(git pull)
https://blog.csdn.net/lindexi_gd/article/details/52554159 (refusing to merge unrelated histories) ht ...
- App自动化-python-Unittest框架
TestCase: 一段Testcase代码示例: # -*- coding: utf-8 -*- ''' Created on 2019-6-27 @author: adminstrator ''' ...
- T2695 桶哥的问题——吃桶 题解
校内测试 ------T3 对于这个题,首先想到的应该就是暴力枚举了吧,看看数据范围,60就是白送的啦!(但是我也不知道怎么才20分qwq) 思路分析: 这个题要你求所有套餐的总价值,先看一眼产生套餐 ...
- maven mvn 命令行 编译打包
* 配置好jdk * 下载安装maven http://maven.apache.org/download.cgi apache-maven-3.3.3-bin.zip * 解压到G:\apache- ...
- php多线程的概念
来源:http://www.cnblogs.com/zhenbianshu/p/7978835.html 多线程 线程 首先说下线程: 线程(thread) 是操作系统能够进行运算调度的最小单位.它被 ...
- Nginx之配置文件的解析
1. ngx_command_t 为了统一配置项目的解析,Nginx 定义了如下数据类型对所有的 Nginx 配置项进行了统一的描述. typedef struct ngx_command_s ngx ...
- iTerm2使用Profiles自动登录
http://blog.csdn.net/wandershi/article/details/75088310 1.创建Profiles文件 cd ~/.ssh/iTerm2SSH/ vi 172.1 ...