const unit_list = [
{
"multi_unit_id": 107132,
"conversion_rate": 1,
"unit_id": 1831,
"unit_use_type": 0,
"unit_no": "P220614183424770",
"unit_type": 0,
"primary_unit": 1,
"unit_name": "个"
},
{
"multi_unit_id": 114003,
"conversion_rate": 2,
"unit_id": 1830,
"unit_use_type": 2,
"unit_no": "P220614644454671",
"retail_price": 1,
"unit_type": 0,
"primary_unit": 1,
"unit_name": "只"
},
{
"multi_unit_id": 107117,
"conversion_rate": 2,
"unit_id": 1832,
"unit_use_type": 1,
"unit_no": "P220614297589925",
"unit_type": 0,
"primary_unit": 0,
"unit_name": "双"
},
{
"multi_unit_id": 116001,
"conversion_rate": 1,
"unit_id": 1831,
"unit_use_type": 1,
"unit_no": "P220614183424770",
"unit_type": 0,
"primary_unit": 1,
"unit_name": "个"
},
{
"multi_unit_id": 107120,
"conversion_rate": 1,
"unit_id": 1831,
"unit_use_type": 2,
"unit_no": "P220614183424770",
"retail_price": 2,
"unit_type": 0,
"primary_unit": 0,
"unit_name": "个"
}
]
// 首先排除unit_use_type !== 2的数据
const arr = unit_list.filter(unit=> unit.unit_use_type !== 2)
function formatArr (arr, key) {
let obj = {}
let newArr = arr.reduce((prev, cur) => {
obj[cur[key]] ? '' : obj[cur[key]] = true && prev.push(cur)
return prev
}, [])
return newArr
}
console