I am trying to delete a key in variable a. However, i still want to keep the original variable value for another purpose. But somehow its alway overwrite the initial a.
This is the code that i wrote:
let a = [
{ firstName: 'Tony', lastName: 'Stack' },
{ firstName: 'Iron', lastName: 'Man' }
];
console.log('before',a);
delete a[0].firstName;
console.log('after',a);
Output:
I am expecting the first console.log will be printing out the initial value.
It's just confuse myself. I feel like i must have missed some knowledge here. Appreciate for any help. Thanks