Is this possible?
So I need to have an array with a dynamic name and content what can be extended 开发者_如何学Goand accessed.
object = {};
var two = ['thing', 'thing2'];
for(one in two){
object[two[one]] = [];
}
If yes but not in this way, then how?
This is definitely doable, just make sure that the object owns the property and it's not inherited from higher up in the prototype chain:
object = {};
var two = ['thing', 'thing2'];
for..in
:
for(var one in two){
if(two.hasOwnProperty(one))
object[two[one]] = [];
}
for
:
for(var i = 0; i < two.length; i++)
object[two[i]] = [];
var object = {};
var props = 'thing thing2'.split(' ');
for (var i=0,len=props.length;i<len;++i){
object[props[i]] = [];
}
精彩评论