gpt4 book ai didi

javascript - 使用过滤器从数组列表中删除重复的数组?

转载 作者:行者123 更新时间:2023-12-02 14:31:52 26 4
gpt4 key购买 nike

我使用这个代码

labels.map((label, key) => {
const xAxis = (parseInt(label, 10)).toFixed(0);
const yAxis = parseInt(this.props.dataSet.datasets[0].data[key], 10);
const arrayAxis = [xAxis, yAxis];
data.push(arrayAxis);
return arrayAxis;
});

然后我得到数据列表

["1", 1] 
["2", 1] // duplicate
["2", 1] // duplicate
["3", 1]
["4", 1]
["4", 1]
["5", 4]
["6", 4]
["7", 4]
["8", 4]
["9", 4]
.....
....
...

如何使用过滤器从数组列表中删除重复的数组?

最佳答案

您可以将其与临时对象一起使用来指示重复项。它也适用于未排序的数组。

levels.forEach((temp => (label, key) => {
var xAxis = (parseInt(label, 10)).toFixed(0),
yAxis = parseInt(this.props.dataSet.datasets[0].data[key], 10),
arrayAxis =[ xAxis, yAxis];
if (!temp[arrayAxis]) {
temp[arrayAxis] = true;
data.push(arrayAxis);
}
})(Object.create(null)));

关于javascript - 使用过滤器从数组列表中删除重复的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37742223/

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