我该怎么写?
0: Object
key: "false"
__proto__: Object
1: Object
key: "blue"
__proto__: Object
他们'键',以某种方式只是“键”:值,对象而不是键内的值。它变得像以下那样。
var chatBox_vars = [{'return_url':chatBox_return_url},{'base_color':chatBox_base_color},
{'mid_color':chatBox_mid_color},
{'init_open':chatBox_init_open},
{'init_open':chatBox_mx_logo},
{'welcome_msg':chatBox_welcome_msg},
{'clientid':chatBox_clientid}];
var chatBox_array = [];
for (var i=chatBox_vars.length;i--;){
var item_6dds3=chatBox_vars[i];
for (var key in item_6dds3) {
if (Object.prototype.hasOwnProperty.call(item_6dds3, key)) {
var val_d65f = item_6dds3[key];
if (val_d65f == null || val_d65f == 'undefined' || val_d65f == ''){} else {
console.log(key);
chatBox_array.push({key:val_d65f});
}
}
}
}
这是完整的代码。
temp = dict(....)
exec("x_dct=" + temp)
items = x_dct.items()
答案 0 :(得分:2)
在设置属性
之前尝试创建对象var obj = {}; obj[key] = val_d65f;
chatBox_array.push(obj);