I have a JSON array containing name/value pairs and I am searching for a more efficient way to update the value for a specific name in the array. For example:
var myArr = [{"name":"start","value":1},{"name":"end","value":15},{"name":"counter","value":"6"},{"name":"user","value":"Bert"}]
Currently, I am using:
$.each(myArr, function (key, pair) {
if (pair.name == 'user')
{
pair.value = 'bob';
}
});
However, with a large number of values in my object, I would prefer a simpler way to modify them without needing an if
statement for each one.
My ideal solution would be something like myArr['user'].value = 'bob';
or a similar approach.