Js data structure reorganization

has the following data structure.


e   test1
b   test2
c   test2
i   test3
d   test3
f   test3
k   test3
h   test3

12


< hr >

:

[
    {
        category: "test1",
        arr: ["e"]
    },
    {
        category: "test2",
        arr: ["b","c"]
    },
    {
        category: "test3",
        arr: ["i","d","k","f","h"]
    }
]



[
    {
        category: "test1"
    },
    {
        category: "test2"
    },
    {
        category: "test3"
    }
].
Mar.10,2021

this is not difficult. You can create a new map, shape such as:

when you get the attribute array.
var cate = new Map()
cate.set('test1', 0)
cate.set('test2', 1)
cate.set('test3', 2)

then traverse the original array:

// 
prop = [
    {
        category: 'test1',
        arr: []
    },
    {
        category: 'test2',
        arr: []
    },
    {
        category: 'test3',
        arr: []
    }
]

// 
for (i in categorys) {
  prop[cate[categorys[i][1]].arr.push(lecategorys[i][0])
}
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-1b3b29c-2c29d.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-1b3b29c-2c29d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?