0

I saw a video about it, its example code is here. The result is "Before delete obj.age there are three attributes(age name color) in the obj, After delete obj.age there are two attributes(name color) in the obj" in the video. But when I try it on my computer (macOS 10.15.7 Catalina Chrome 97.0.4692.71), Whether before or after, the console.log results are same ---here are two attributes(name color) in the obj

var obj = {};
obj.name = 'canoe';
obj.age = 1;
obj['color'] = 'blue';
console.log(obj.age);
//before delete age
console.log(obj);
delete obj.age;
//After delete age
console.log(obj);

The result in my computer is:

1
{
  "name": "canoe",
  "color": "blue"
}
{
  "name": "canoe",
  "color": "blue"
}
  • it works in node.js and chrome too – MWO Jan 12 '22 at 07:50
  • you just delete the age attribute before : { "name": "canoe", "age": 1, "color": "blue" } After: { "name": "canoe", "color": "blue" } – mshehata Jan 12 '22 at 07:51
  • yes but in my computer : before delete age; "console.log" 's result is {"color": "blue", "name": "canoe" } ; after delete age; "console.log" 's result is {"color": "blue", "name": "canoe" }; – Nichts__97 Jan 12 '22 at 07:56
  • Stop before deleting and expand the logged object. Then delete, log again and expand the result. See the second linked duplicate. – Salman A Jan 12 '22 at 07:56
  • If you consider [this](https://github.com/nodejs/node/issues/11568#issuecomment-283856965), a possible solution to have a sync `console.log` could be [this](https://github.com/nodejs/node/issues/11568#issuecomment-348681867) – Giovanni Esposito Jan 12 '22 at 08:00
  • Thanks everybody. I know it now. Thanks! – Nichts__97 Jan 12 '22 at 08:07

0 Answers0