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

  1. Array.prototype.filter()的实现

    来源 今年某前端笔试的一道题,大概就是实现一遍filter,包括一个可以改变上下文的要求,其实就是改变this啦,跟原生的filter一样的功能跟参数. 解析 filter的功能就是过滤,传入一个函数 ...

  2. JavaScript的Array.prototype.filter()详解

    摘抄与:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/filter 概述 ...

  3. Array.prototype.filter(Boolean)

    ES5 中的数组有这个方法:Array.prototype.filter ,具体使用参考MDN,这里讲一个特殊应用: 回顾下语法: new_array = arr.filter(callback[, ...

  4. 数组的方法之(Array.prototype.filter() 方法)

    filter() 方法创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素.     注意: filter() 不会对空数组进行检测.     注意: filter() 不会改变原始 ...

  5. javascript替代Array.prototype.some操作

    Array.prototype.some在低版本浏览器好像不太兼容,下列是替代方法 一. for 循环 const initIds: any[] = [1,2,3]; const Ids: any[] ...

  6. 数组方法 Array.prototype

    Object.prototype 数组的值是有序的集合,每一个值叫做元素,每一个元素在数组中都有数字位置编号,也就是索引,js中数组是弱类型的,数组中可以含有不同类型的元素.数组元素甚至可以是对象或者 ...

  7. 来自数组原型 Array.prototype 的遍历函数

    1. Array.prototype.forEach() forEach() 是一个专为遍历数组而生的方法,它没有返回值,也不会改变原数组,只是简单粗暴的将数组遍历一次  参数: callback() ...

  8. Array.prototype

    Array.prototype  属性表示 Array 构造函数的原型,并允许您向所有Array对象添加新的属性和方法. /* 如果JavaScript本身不提供 first() 方法, 添加一个返回 ...

  9. Array.prototype.map()和Array.prototypefilter()

    ES5 => 筛选功能  Array.prototypefilter(): 代码: var words = ['spray', 'limit', 'elite', 'exuberant', 'd ...

随机推荐

  1. 百度人脸识别java html5

    1.前端thymeleaf+h5 index.html    人脸识别+定位,用的百度sdk <!DOCTYPE html> <html xmlns="http://www ...

  2. go mod 解决 Go 语言的包依赖问题

    转:https://testerhome.com/topics/16980 https://testerhome.com/ -------------------------------------- ...

  3. WebRTC基于GCC的拥塞控制算法[转载]

    实时流媒体应用的最大特点是实时性,而延迟是实时性的最大敌人.从媒体收发端来讲,媒体数据的处理速度是造成延迟的重要原因:而从传输角度来讲,网络拥塞则是造成延迟的最主要原因.网络拥塞可能造成数据包丢失,也 ...

  4. Force git to overwrite local files on pull 使用pull强制覆盖本地文件 转载自:http://snowdream.blog.51cto.com/3027865/1102441

    How do I force an overwrite of local files on a git pull? I think this is the right way: $ git fetch ...

  5. Django+MySQLDB配置

    Django+MySQLDB配置   来源: ChinaUnix博客 日期: 2009.07.09 16:25 (共有条评论) 我要评论                   一.安装Mysql(1)下 ...

  6. [Algorithm] Chunk Array

    // --- Directions// Given an array and chunk size, divide the array into many subarrays// where each ...

  7. IAT表和导入表

    1.关于IAT(import address table)表 当exe程序中调用dll中的函数时,反汇编可以看到,call后面并不是跟的实际函数的地址,而是给了一个地址:

  8. 第四届西安邮电大学acm-icpc校赛 热狗树

    题目描述  “我是番茄酱!”“我是黄芥末酱!”“合在一起就是——美式热狗上加的,那个!“热狗树上的每个节点都涂有番茄酱或者黄芥末酱中的一种,这样热狗树就变得美味了~LiMn2O4构造了一颗热狗树,他想 ...

  9. delphi将字符串转换成stringlist

    function StrToList(const sString, Token: string): TStringList;var sTmp: string; iPos: Integer; Tokle ...

  10. 下载eclipse 配置eclipse 新建Java项目 写一个小程序 运行

    为了更好的学习java,我打算下载个eclipse 地址:https://www.eclipse.org/downloads/packages/ 我们需要下载的版本是Eclipse IDE for J ...