3 回答
TA贡献1875条经验 获得超5个赞
let data = [
{ name: "小明", status: false },
{ name: "小红", status: false },
{ name: "小张", status: true },//一次出现
{ name: "小墙", status: false },
{ name: "小粉", status: false },
{ name: "小军", status: false },
{ name: "小钰", status: false },
{ name: "小访", status: true },//二次出现
{ name: "小源", status: false },
{ name: "小方式", status: false },
{ name: "小佛", status: true },//三次出现 三次之后 还有true的变为false
{ name: "小付款", status: true },
{ name: "小哦咯", status: true },
{ name: "小来了", status: false },
];
let count = 0;
data.forEach(obj => {
if (count >= 3) {
obj.status = false;
return;
}
if (obj.status) {
count++;
}
})
console.log(data);
TA贡献1806条经验 获得超5个赞
let total = 0;
let result = data.map(k => {
if(k.status) {total++};
if(total>3 && k.status) {k.status=false}
return k;
});
TA贡献1804条经验 获得超3个赞
let count = 0;
for(let item of data){
if(count < 3){
item.status && ++count
}else{
item.status = false;
}
}
- 3 回答
- 0 关注
- 184 浏览
添加回答
举报