请问一下大家,怎么bb对象转换为dd这种形式,需要设用于ie浏览器,谢谢。

Reset
  • 24
 var  bb =[{
        "x": "0.008361",
        "y": "0.005587"
    }, {
        "x": "0.991639",
        "y": "0.019553"
    }, {
        "x": "0.991639",
        "y": "0.986033"
    }, {
        "x": "0.006689",
        "y": "0.980447"
    }];
   var dd= [
        [
            0.008361,
            0.005587
        ],
        [
            0.991639,
            0.019553
        ],
        [
            0.991639,
            0.986033
        ],
        [
            0.006689,
            0.980447
        ]
    ]
回复
阅读 1k
1 个回答
donglegend
  • 905
✓ 已被采纳

如果数据结构是稳定的,大概参考一下:

function helpTransform(data) {
    var result = []
    var isArray = Object.prototype.toString.call(data) === '[object Array]'
    if (!isArray) {
        return result
    }
    for(var i = 0, len = data.length; i < len; i++) {
        var temp = data[i]
        var arr = [temp.x, temp.y]
        result.push(arr)
    }
    return result
}
var dd = helpTransform(bb)
宣传栏