0

I am trying to create a function “updateProp” that has the following parameters:

“obj” - an object to update

“keyName” - a key name to update on the object

“val” - the new value to assign to the key

“updateProp” should update the object passed in based on the “keyName” and “val” pair given and should return the object that was passed in

I started with:

function updateProp(obj, keyName, val){
    
}
    

I am expecting a result such as:

const wallet = {
    color: 'Black',
    hasCash: true
}
updateProp(wallet, 'color', 'Blue'); => { color: 'Blue', hasCash: true }

I don’t know how I should write out the function in order for it to perform the action I want above

isherwood
  • 58,414
  • 16
  • 114
  • 157
Imam
  • 15
  • 5

1 Answers1

0

Need to assign object key that value like this

function updateProp(obj, keyName, val){
        obj[keyName]=val
    }
Pankti Shah
  • 141
  • 8