-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
  • 21,961
  • 19
  • 54
  • 57
Swaroop Maddu
  • 4,289
  • 2
  • 26
  • 38

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,444
  • 14
  • 18