📌  相关文章
📜  我如何将对象转换为数组 javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:50.556000             🧑  作者: Mango

代码示例4
function arrayToObject(arr) {
    var obj = {};
    for (var i = 0; i < arr.length; ++i){
        obj[i] = arr[i];
    }
    return obj;
}
var colors=["red","blue","green"];
var colorsObj=arrayToObject(colors);//{0: "red", 1: "blue", 2: "green"}