博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Javascript] The Array filter method
阅读量:5276 次
发布时间:2019-06-14

本文共 889 字,大约阅读时间需要 2 分钟。

One very common operation in programming is to iterate through an Array's contents, apply a test function to each item, and create a new array containing only those items the passed the test. For example, let's say you wanted to loop through an array of stocks and select only those with the price larger than a certain value. In this lesson we will demonstrate how to use the Array's filter method to easily perform this operation with less code than a loop would require.

 

function getStocksOver(stocks, minPrice) {  return stocks.filter(function(stock) {    return stock.price >= minPrice;  })}var expensiveStocks = getStocksOver([  { symbol: "XFX", price: 240.22, volume: 23432 },  { symbol: "TNZ", price: 332.19, volume: 234 },  { symbol: "JXJ", price: 120.22, volume: 5323 },],150.00);console.log(JSON.stringify(expensiveStocks));

 

转载于:https://www.cnblogs.com/Answer1215/p/4356391.html

你可能感兴趣的文章
[LeetCode] Merge Intervals
查看>>
【翻译自mos文章】当点击完 finishbutton后,dbca 或者dbua hang住
查看>>
Linux编程简介——gcc
查看>>
2019年春季学期第四周作业
查看>>
MVC4.0 利用IActionFilter实现简单的后台操作日志功能
查看>>
rotate the clock
查看>>
bugku 变量
查看>>
数据库01 /Mysql初识以及基本命令操作
查看>>
数据库02 /MySQL基础数据类型以及多表之间建立联系
查看>>
Python并发编程04/多线程
查看>>
CF461B Appleman and Tree
查看>>
CF219D Choosing Capital for Treeland
查看>>
杂七杂八的小笔记本
查看>>
51Nod1353 树
查看>>
CF1215E Marbles
查看>>
BZOJ2339 HNOI2011卡农(动态规划+组合数学)
查看>>
octave基本操作
查看>>
axure学习点
查看>>
WPF文本框只允许输入数字[转]
查看>>
dom4j 通用解析器,解析成List<Map<String,Object>>
查看>>