简体   繁体   English

如何过滤 javascript 中的弹性查询?

[英]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.例如,我想删除数组中包含 item2 的元素。 I want to check if the item2 key exists and delete that item if it is.我想检查 item2 键是否存在,如果存在则删除该项目。 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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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