我想从一个存储在字符串变量proyNombre上的键获取值,但每当我通过常用方法“myAssociativeArray.MyKey”调用它时,它将获取变量'proyNombre'作为键,而不是获取其值并通过它作为一个关键。如何从javascript中的关联数组中获取“动态”值?
proyectos.each(function(index){
var proyNombre = this.value;
if(!(proyNombre in myArray)){ // whenever the variable is undefined, define it
myArray[proyNombre] = horas[index].value-0 + minutos[index].value/60;
}
else{
console.log(myArray.proyNombre); //This doesnt work, it tries to give me the value for the key 'proyNombre' instead of looking for the proyNombre variable
console.log(myArray.this.value); //doesnt work either
}
});
请注意,JavaScript没有关联数组 - 只是对象。 – alex 2010-12-03 01:58:24