我想從一個存儲在字符串變量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