мне нужно отфильтровать массив с двумя условиями angular 8 - PullRequest
0 голосов
/ 30 января 2020

Мне нужно отфильтровать массив с двумя условиями с null и ''

items:any=[
  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 

  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 

  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 

  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 

  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 
  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 

  {
    amount     : '',
    payee_name        : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }, 

  {
    amount     : '',
    payee_name   : '',
    misc :'',
    type    :'',
    status  : "cash",
    identify:Math.floor(Math.random() * 100) + 1  ,
   is_check       : 1
  }    
];

let p;

p=this.items.filter(item  => item.amount  !== ''||null);

1 Ответ

0 голосов
/ 30 января 2020

Попробуйте так.

let items: any[] = [
      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },

      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },

      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },

      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },

      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },
      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },

      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      },

      {
        amount: '',
        payee_name: '',
        misc: '',
        type: '',
        status: "cash",
        identify: Math.floor(Math.random() * 100) + 1,
        is_check: 1
      }
    ];
    let data = items.filter(e => e.amount != "" && e.amount != null) 
    console.log(data);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...