我知道有push()将oject添加到数组中。但是如何将对象添加到对象中。
var osubcategories = {};
for (var i=0; i<data.length; ++i){
var tempkey = data[i].scid; // here tempkey will be any number sat 15 20 30 etc
// how to add this tempkey along with true in osubcategories
}
我希望循环中的每个tempkey都有这样的输出:
osubcategories = {"15" : true, "23": true, "55" : true}
答案 0 :(得分:1)
var osubcategories = {};
for (var i=0; i<data.length; ++i){
var tempkey = data[i].scid; // here tempkey will be any number sat 15 20 30 etc
// the following line will add the properties to the "osubcategories" object
osubcategories[tempKey] = true;
}