I have a simple function that updates the values of an object. Currently, the function takes in 3 parameters to updated the object. I would like an optional fourth parameter that will accept an array of objects (array) and change the values for all the objects in the array. If the fourth parameter is provided I would like to ignore the others. What is the best way to do this? Thanks
var myObj = {myKey : 0}
var obj1 = {myKey : 0}
var obj2 = {myKey : 0}
var array = [{obj: obj1, key: 'myKey1', value: 1},{obj: obj2, key: 'myKey2', value: 2}]
function changeRule(obj, key, value) {
obj[key] = value
},
changeRule(myObj, 'myKey', 1)