[Solved] how to map many arrays values that have same construct to an object?


my solution.

I like just using the ES6(es2015+) way.

const test_array = [
    {
        "name": "AnyManagedFundsRow",
        "columnMeta": {
            "a0": "STRING",
            "a1": "STRING",
            "a2": "STRING",
            "a3": "DATE",
            "a4": "DATE",
            "a5": "DOUBLE",
            "a6": "INT"
        },
        "rows": [
            [
                "华夏基金管理有限公司",
                "华夏大中华企业精选灵活配置混合(QDII)",
                "其他型基金",
                "2016-01-20",
                "",
                21.877086009428236,
                65135
            ],
            [
                "华夏基金管理有限公司",
                "华夏大盘精选混合",
                "混合型基金",
                "2015-09-01",
                "2017-05-02",
                10.307680340705128,
                2944
            ]
        ]
    }
];


/**
 * ES6 solution
 *
 */


let keys = Object.keys(test_array[0].columnMeta),
    types = Object.values(test_array[0].columnMeta),
    target_objects = test_array[0].rows.map(
    (arr) => {
        let obj = {};
        arr.forEach(
            (item, i) => {
                obj[keys[i]] = {};
                obj[keys[i]].Description = `${item}`;
                obj[keys[i]].type = types[i];
            }
        );
        return obj;
    }
);

console.log(`solution =\n`, JSON.stringify(target_objects, null, 4));

demo

enter image description here

solved how to map many arrays values that have same construct to an object?