使用 Lodash 使用索引从对象中删除项目
Remove items from Object using their Index using Lodash
我有一个这样的对象:
[
[
'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)
我设法使用以下代码修复它:
positions.forEach((position) => {
//removes duplicates for a clearer print
const pos = _.omit(position, [0, 1, 2, 3, 4])
})
我有一个这样的对象:
[
[
'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)
我设法使用以下代码修复它:
positions.forEach((position) => {
//removes duplicates for a clearer print
const pos = _.omit(position, [0, 1, 2, 3, 4])
})