let permissionId = [] for (const i in menuList) { for (const j in permission) { if (menuList[i].id == permission[j].id) { permissionId.push(menuList[i].id) } } }
以上代码如何优化为.map的写法呢
在这里先谢谢各位大神们的解答了,小弟感激不尽!
const map = permission.reduce((r, i) => (r[i.id] = true, r), {}) const permissionId = menuList.filter(i => !!map[i.id]).map(i => i.id)
2.1m questions
2.1m answers
60 comments
57.0k users