如果对象名来自另一个数组,如何将对象添加到数组?

时间:2017-02-22 10:58:19

标签: javascript

var streamerStatus = [];

var streamers = ['x', 'y', 'z'];

for (var i = 0; i < streamers.length; i++){

streamerStatus.push({streamers[i]: 'OFFLINE'});

}

1 个答案:

答案 0 :(得分:0)

for (var i = 0; i < streamers.length; i++){
  var obj = {};
  obj[streamers[i]] = 'OFFLINE';

  streamerStatus.push(obj);
}