有时候我们想筛选出一个对象列表中符合某个属性特征的列表,这个时候我们就可以使用js中的filter功能了。
###用法
1 | xxx.filter(function(currentValue,index,arr), thisValue) |
function可接收参数
function(currentValue, index,arr)
①currentValue:必须。当前元素的值
②index:可选。当前元素的索引值
③arr:可选。当前元素属于的数组对象
返回对象中字段值大于2的字段
1 | var data = {a:1,b:2,c:3,d:4}; |
例2:返回数组中所有的偶数
1 | var arr = [1,2,3,4,5,6,7,8,9,10]; |