-1

I am trying to use a variable to update the map object but it inserts a new key:value pair. Using task."$key" = value; throws an error.

const task = {
    title : 'update UI for Login',
    description:'update UI for Login',
    status : 'open'
}

const update = (key,value) =>{
  task.key = value;
}

console.log(task);
update('title','Sign Up');
console.log(task);
Zsolt Meszaros
  • 15,542
  • 12
  • 36
  • 40
Maddu Swaroop
  • 3,277
  • 2
  • 18
  • 32

1 Answers1

1

You should use [] to access the key,value pair when accessing an Object by variables

const update = (key,value) => {
  task[key] = value;
}
kevinluo201
  • 1,224
  • 11
  • 13