How to update array value javascript?
"But i want to know a better way to do this, if there is one ?"
Yes, since you seem to already have the original object, there's no reason to fetch it again from the Array.
function Update(keyValue, newKey, newValue)
{
keyValue.Key = newKey;
keyValue.Value = newValue;
}
Why not use an object1?
var dict = { "a": 1, "b": 2, "c": 3 };
Then you can update it like so
dict.a = 23;
or
dict["a"] = 23;
If you wan't to delete2 a particular key, it's as simple as:
delete dict.a;
1 See Objects vs arrays in Javascript for key/value pairs.
2 See the delete
operator.