我在 javacsript 中有一个包含 3 个 keyValue 构造函数对象的数组:
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"));
我还有一个函数“更新”,它获取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;
}
但如果有的话,我想要一种更好的方法来做到这一点。