js构建动态对象数组

//定义对象value值数组,obj数组

var value_arry=["aaa","bbb"],obj_arry=[];

for(var i=0;i

var obj={"key1":"值1","key2":"值二"};

obj["key3"]=arry[i];

obj_arry.push(obj);

}

console.log(obj_arry);

输出结果:

[
    {
        "key1": "值1",
        "key2": "值二",
        "key3": "aaa"
    },
    {
        "key1": "值1",
        "key2": "值二",
        "key3": "bbb"
    }

]

做一个需求后台传参数类型是list,动态拼装.

你可能感兴趣的:(js知识)