js不固定表头数据处理

原数据:

"head5": {
                "x0": [
                    0,
                    0,
                    0,
                    4.6,
                    5
                ],
                "x1": [
                    3.5,
                    3,
                    3.2,
                    3.1,
                    3.6
                ],
                "x2": [
                    1.4,
                    1.4,
                    1.3,
                    1.5,
                    1.4
                ],
                "x3": [
                    0.2,
                    0.2,
                    0.2,
                    0.2,
                    0.2
                ],
                "y": [
                    "Iris-setosa",
                    "Iris-setosa",
                    "Iris-setosa",
                    "Iris-setosa",
                    "Iris-setosa"
                ]
            },

目标数据结构:

head5: [
{
x0: 0
x1: 3.5
x2: 1.4
x3: 0.2
y: "Iris-setosa"},
{
x0: 0
x1: 3
x2: 1.4
x3: 0.2
y: "Iris-setosa"},
{
x0: 0
x1: 3.2
x2: 1.3
x3: 0.2
y: "Iris-setosa"
},
{
x0: 4.6
x1: 3.1
x2: 1.5
x3: 0.2
y: "Iris-setosa"
},
{
x0: 5
x1: 3.6
x2: 1.4
x3: 0.2
y: "Iris-setosa"
}
]
mounted() {
        let titleArr = Object.keys(this.head5)
        let contentArr = Object.values(this.head5)
        const num = contentArr[0].length
        var dataArr = []
        for (var index = 0; index < num; index++) {
            var obj = {}
            titleArr.forEach(el => {
                this.$set(obj, el, this.head5[el][index])
            });
            dataArr.push(obj)
        }
}

dataArr则为目标数据

你可能感兴趣的:(js不固定表头数据处理)