我知道从一个键中获取唯一值-unique_by('.[].name)
我想通过检查两个键中的唯一值来获取输出
但是如何处理像unique_by('.[].name,.[].url')
这样的两个键并返回输入沿着其他键呢?
输入
[
{
"name": "abc",
"url": "https://aa.com",
"created_at": "2022-09-30T11:17:33.181Z"
},
{
"name": "bb",
"url": "https://ddd.com",
"created_at": "2022-09-30T11:14:33.180Z"
},
{
"name": "abc",
"url": "https://aa.com",
"created_at": "2022-09-30T11:14:33.180Z"
}
]
预期输出
[
{
"name": "abc",
"url": "https://aa.com",
"created_at": "2022-09-30T11:17:33.181Z"
},
{
"name": "bb",
"url": "https://ddd.com",
"created_at": "2022-09-30T11:14:33.180Z"
}
]
2条答案
按热度按时间7vhp5slm1#
将条件收集到数组中:
nfs0ujit2#
只需向
unique_by
提供一个包含所有内容的数组,以便该数组必须是唯一的:Demo