gpt4 book ai didi

javascript - Lodash uniqBy 数组的倍数?

转载 作者:行者123 更新时间:2023-12-03 23:28:49 26 4
gpt4 key购买 nike

我有数组:

[ [ '245', '0', '0.0100', '245,0,0.01' ],
[ '245', '1', '0.0100', '245,1,0.01' ],
[ '208', '0', '0.0300', '208,0,0.03' ],
[ '208', '0', '0.0500', '208,0,0.05' ],
[ '208', '0', '0.0600', '208,0,0.06' ] ]

我需要通过 [0][1] 单元格获取唯一数组像这样:

[ [ '245', '0', '0.0100', '245,0,0.01' ],
[ '245', '1', '0.0100', '245,1,0.01' ],
[ '208', '0', '0.0600', '208,0,0.06' ] ]

请帮忙/

最佳答案

使用 lodhash uniqBy() 方法

var data = [
['245', '0', '0.0100', '245,0,0.01'],
['245', '1', '0.0100', '245,1,0.01'],
['208', '0', '0.0300', '208,0,0.03'],
['208', '0', '0.0500', '208,0,0.05'],
['208', '0', '0.0600', '208,0,0.06']
];

console.log(
_.uniqBy(data, function(v) {
return v[0] + ' ' + v[1];
})
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.13.0/lodash.js"></script>

关于javascript - Lodash uniqBy 数组的倍数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37394029/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com