1. let list = [
    2. {
    3. customUrl: "www.aa.com",
    4. showFlag: null,
    5. showOrder: 0,
    6. title: "电脑维修1",
    7. titleTag: "热门1"
    8. },
    9. {
    10. customUrl: "www.bb.com",
    11. showFlag: null,
    12. showOrder: 0,
    13. title: "电脑维修2",
    14. titleTag: "热门1"
    15. },
    16. {
    17. customUrl: "www.cc.com",
    18. showFlag: null,
    19. showOrder: 0,
    20. title: "电脑自购1",
    21. titleTag: "其他"
    22. },
    23. {
    24. customUrl: "www.dd.com",
    25. showFlag: null,
    26. showOrder: 0,
    27. title: "电脑自购2",
    28. titleTag: "其他"
    29. }
    30. ]
    31. const m = new Map();
    32. list.map(item => {
    33. m.set(item.titleTag, [...(m.get(item.titleTag) || ''), item.customUrl])
    34. })
    35. const newList = Object.fromEntries(m.entries())
    36. console.log("根据titleTag值筛选出字段curstomUrl值:", newList)
    37. // 进行遍历
    38. for (let key in newList) {
    39. if (key === Object.keys(newList)[0]) {
    40. console.log("拿到热门的内容包含的值:", newList[key])
    41. const obj = newList[key]
    42. let newObj = Object.keys(obj).map(e => {
    43. return {
    44. title: obj[e]
    45. }
    46. })
    47. console.log('重新组合后的值', newObj)
    48. } else {
    49. console.log("其他的内容的值:", newList[key])
    50. }
    51. }