Js N multi-layer (indefinite) nested loop change json key value method outputs a complete new list object

data children is uncertain, and js functions deal with data separately, just like changing name to tile,value to key,
if the children array is empty, then output isLeaf:true, otherwise, continue to cycle to change the subitems
to solve.
the data structure is as follows

list = [
    {
        name: "0",
        value: "0",
        children: [
            name: "0-1",
            value: "0-1",
            children: [
                name: "0-2",
                value: "0-2",
                children: [
                    // ...
                ],
                // ...
            ]
        ]
    },
];
Mar.09,2022

for the moment, it means that the output isLeaf: true is to add this attribute to the data whose children is empty. The code is as follows


function transform(list) {
    if (Array.isArray(list) && list.length !== 0) {
        list = list.map(v => {
            v.title = v.name
            v.key = v.value
            delete v.name
            delete v.value
            if (!transform(v.children)) {
                v.isLeaf = true
            }
            return v
        })
        return list
    } else {
        return false
    }
}

console.log(transform(list))
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-1e98e0b-1715.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-1e98e0b-1715.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?