the array operation of js has always been a headache for me. In the past, dealing with arrays is a variety of foreach nesting, filter,map. After writing, I always feel that there will be some optimization, but I really don"t know how to optimize it because of my limited ability. The code is as follows:
let arr = [{
id: 10,
name: "IOS",
status: false
}, {
id: 11,
name: "Android",
status: false
},
{
id: 12,
name: "",
status: false
},
{
id: 13,
name: "",
status: false
},
{
id: 20,
name: "PC",
status: true
}]
// statustrueid
let arr2 = arr.filter(item => item.status)
let arr3 = arr2.map(item => item.id)
let str = arr3.join(",")
ask all the bosses for advice.