IはjavacsriptでkeyValueのコンストラクタの3つのオブジェクトの配列を有する:配列値のjavascriptを更新するには?
function keyValue(key, value){
this.Key = key;
this.Value = value;
};
var array = [];
array.push(new keyValue("a","1"),new keyValue("b","2"),new keyValue("c","3"));
IもkeyValue object as parameter
を取り、アレイ内のそのオブジェクトの値を更新する機能「更新」を有する:
function Update(keyValue, newKey, newValue)
{
//Now my question comes here, i got keyValue object here which i have to
//update in the array i know 1 way to do this
var index = array.indexOf(keyValue);
array[index].Key = newKey;
array[index].Value = newValue;
}
を
しかし、もしあればこれを行うより良い方法が欲しい。
なぜオブジェクトを使用しないのですか? 'dict.a = 23;'または 'dict [" a "] = 23のように更新することができます; '... – canon
キヤノンの応答は答えになる可能性があります –
@AndréPena私は答えにそれを昇格させました。 – canon