zoukankan      html  css  js  c++  java
  • js 根据 数组条件 简单查询的方法临时保存

        let array = [{
            date: '2016-05-02',
            name: 'Ethan',
            status: 'success',
            total: '81'
          },
          {
            date: '2016-05-04',
            name: 'Lynn',
            status: 'fail',
            tag: '50'
          },
          {
            date: '2016-05-01',
            name: 'Kevin',
            status: 'success',
            tag: '20'
          }
        ];
        let filterStatus = "success";
        let filterNames = ['Lynn', 'Kevin'];
        let result = array.filter((a, i) => {
          return (a.status === filterStatus && filterNames.some(f => (f === a.name)))
    
          //filterNames.map--------------
          // 0:
          //   date: "2016-05-02"
          // name: "Ethan"
          // status: "success"
          // total: "81"
          // __proto__: Object
    
    
          // 1:
          //   date: "2016-05-01"
          // name: "Kevin"
          // status: "success"
          // tag: "20"
          // map-----
    
          //filterNames.some  ---weiyi
    
          //   date: "2016-05-01"
          // name: "Kevin"
          // status: "success"
          // tag: "20"

    方法2:

    let keys = Object.keys(filters)
    let result = array.filter(item => {
      return keys.every(key => filters[key].indexOf(item[key]) !== -1)
    })
  • 相关阅读:
    干草金字塔
    ⑨的完美搭积木
    门(door)
    ⑨的完美冻青蛙(frog)
    An overnight dance in discotheque
    逃跑(escape)
    BZOJ4390: [Usaco2015 dec]Max Flow
    BZOJ3732: Network
    BZOJ1121: [POI2008]激光发射器SZK
    BZOJ3713: [PA2014]Iloczyn
  • 原文地址:https://www.cnblogs.com/autoXingJY/p/11422101.html
Copyright © 2011-2022 走看看