Array splitting problem

 datalist: [
          {categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
          {categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
          {categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
          {categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
          {categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
          {categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
          {categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
          {categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
          
        ]

split into several arrays according to categoryName. How should I write it?

[{categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
{categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
{categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},];
[{categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
{categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},]
[{categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
 {categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},
 {categoryId: "f5665104-cff9-47c9-b44c-b92694e45767", categoryName: ""},]
Mar.20,2021

//var data = {}
var data = {sort:[]}
datalist.forEach((item,index)=>{
    var s = item.categoryName
    data[s] ? data[s].push(item) : (data[s] = [item],data.sort.push(s))
    //data[s] ? data[s].push(item) : data[s] = [item]
})
//data = Object.values(data)
//objectsort
data = data.sort.map((item,index)=>{
    return data[item]
})
< hr >

hurry up below

var data = []
datalist.forEach((item,index)=>{
    if(data.length == 0 || item.categoryName!==data[data.length-1][0].categoryName){
        data.push([])
    }
    data[data.length-1].push(item)
})

landlord, if you have already arranged the order, do you want this effect:

var newDataArray = dataList.reduce((target,current)=>{
    if(target[target.length-1] == null || target[target.length-1][target[target.length-1].length - 1].categoryName !== current.categoryName) {
        target.push([current])
    } else {
        target[target.length-1].push(current)
    }
    return target

}, []);

console.log(newDataArray)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e511-2bb7e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e511-2bb7e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?