Q:

Javascript: Delete/Edit Object within Object

I have users defined as such;
const initUsers = {
  'a@test.com':{
    firstName: 'A',
    lastName: 'Test',
    email: 'a@test.com',
    password: 'test',
  },
  'b@test.com':{
    firstName: 'B',
    lastName: 'Test',
    email: 'b@test.com',
    password: 'test',
  }
};

I am able to retrieve a user by doing initUser['a@test.com']. How do I delete the users based on their key which is the email like a@test.com? Or how do I replace it with another key, for example, c@test.com in place of a@test.com?
Thank you.
(JavaScript Beginner)

A:

Use Javascript delete keyword to delete objects' properties
delete initUsers['a@test.com']
Should delete it for you
You can't change a property's name of an object. Best bet is to add the new property to the object and delete the one you want to replace

