gpt4 book ai didi

ios - 从数组中删除重复数据

转载 作者:行者123 更新时间:2023-11-28 19:25:45 29 4
gpt4 key购买 nike

我有 2 个数组。

const finalArr = [] 

const arr = ["abc","def"]
const arr2 = [
{ name: "abc", refresh: false },
{ name: "efd", refresh: false },
{ name: "def", refresh: false }
]

现在我正在尝试将 arr2 的刷新值更新为 true 以匹配来自 arr 的名称,它返回重复值:

这是我的代码:

arr2.map(obj => {
arr.map(name => {

if (obj.name === name){
finalArr.push({ ...obj, refresh: true })
} else{
finalArr.push({ ...obj, refresh: false })
}
})

谁能告诉我它有什么问题吗?

最佳答案

这很简单:

const finalArray = arr2.map(obj => {
return { ...obj, refresh: arr.includes(obj.name) };
}

关于ios - 从数组中删除重复数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58381067/

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