I have an array of 3 objects of keyValue constructor in javacsript:
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 also have a function 'Update' which takes keyValue object as parameter and updates the value of that object in the array:
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;
}
But I want a better way to do this if there is one.
var dict = { "a": 1, "b": 2, "c": 3 };and then you can update it likedict.a = 23;ordict["a"] = 23;...