JS filter() 的使用

filter 方法

filter 方法返回一个新数组,新数组的元素是原数组中经过符合指定筛选条件的全部元素。javascript

filter 具体参数

Array.filter(function(value,index,arr),thisValue)
eg.java

items = [{"name":"test1", "value":222}, {"name":"tttt", "value":"333"}]

items.filter(function(){console.log(arguments)})

bVvP8s?w=372&h=289

自定义从新过滤

eg.数组

const filterByName = a => b => {
  return b.name.indexOf(a) > -1
}

items = items.filter(filterByName('te'))

即筛选出数组中name属性包含‘te’的对象this

换成ES5的写法,即spa

function a (a){
   return function (b, index, arr){
          return b.name.indexOf(a) > -1
}
}