Answers for "how to transpose json data"

0

how to transpose json data

transpose : function(oTreeAll) {

    var keys = [];
    var i = 0;
    for ( var key in oTreeAll[i]) {
        keys.push(key);
    }

    console.log(keys);

    var newObj = {
        d : []
    };

    newObj['length'] = oTreeAll.length;
    for (var k = 0; k < oTreeAll.length; k++) {
        var obj = {};
        for ( var cnt in keys) {
            obj[keys[cnt]] = "";
        }
        newObj.d.push(obj);
    }

    for (var k = 0; k < oTreeAll.length; k++) {
        for (var j = 0; j < oTreeAll.length; j++) {
            newObj.d[k][keys[j]] = oTreeAll[j][keys[k]];
        }
    }

    console.log(newObj);
            return newObj;

},
Posted by: Guest on March-12-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language