Is this possible?
So I need to have an array with a dynamic name and content what can be extended and 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 on one, causing it to be globally defined (and potentially collide).
Arraywithfor-inis considered bad practice; use a C-styleforloop or useArray.prototype.forEachif available.onevariable, unless you havevar oneelsewhere in your function. Best practice for iterating properties of an object isfor (var prop in obj){ if (obj.hasOwnProperty(prop)){ ... } }.