【问题标题】:Remove items from Object using their Index using Lodash使用 Lodash 使用索引从对象中删除项目
【发布时间】:2021-03-10 17:04:31
【问题描述】:

我有一个这样的对象:

[
  [
    'gfhasd',
    '0x0000000000000000000000000000000000000000',
    '3000000000000000000',
    '0',
    '0x',
    component: 'rgr',
    module: '0x0000000000000000000000000000000000000000',
    unit: '5000000000000000000',
    positionState: '0',
    data: '0x'
  ],
  [
    'zaradf',
    '0x0000000000000000000000000000000000000000',
    '500000000',
    '0',
    '0x',
    component: 'xyx',
    module: '0x0000000000000000000000000000000000000000',
    unit: '500000000',
    positionState: '0',
    data: '0x'
  ]
]

我希望删除每个项目的索引 0,1,2,3,4,因为它们是重复的。

我正在用 lodash 尝试这样的事情,但它不起作用:

const pos = _.remove(positions, (item) => item[i] == 0)

【问题讨论】:

    标签: node.js lodash javascript-objects


    【解决方案1】:

    我设法使用以下代码修复它:

    positions.forEach((position) => {
        //removes duplicates for a clearer print
        const pos = _.omit(position, [0, 1, 2, 3, 4])
    })
    

    【讨论】:

      猜你喜欢
      • 2014-07-18
      • 2017-03-12
      • 2016-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多