简体   繁体   中英

How can I filter elastic query in javascript?

I want to filter elastic query. I added item but i can't remove item. My array is below. For example, I want to delete the element containing item2 in my array. I want to check if the item2 key exists and delete that item if it is. How can I do?

let array = [
    {
      terms: {
        item1: [
          '1111111111111',
          '2222222222222',
          '3333333333333',
          '4444444444444'
        ]
      }
    },
    {
      terms: {
        item2: [
          'aaaaaaaaaaaaaaaaaaaaaaa',
          'bbbbbbbbbbbbbbbbbbbbbbb',
          'ccccccccccccccccccccccc'
        ]
      }
    },
    {
      range: {
        item3: {
          from: 0,
          to: 99999
        }
      }
    }
  ];

Something like this?

 let array = [{ terms: { item1: [ '1111111111111', '2222222222222', '3333333333333', '4444444444444' ] } }, { terms: { item2: [ 'aaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbb', 'ccccccccccccccccccccccc' ] } }, { range: { item3: { from: 0, to: 99999 } } } ]; const filtered = array.filter((el) =>.el[Object.keys(el)[0]].hasOwnProperty('item2')) console.log(JSON.stringify(filtered))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM