javascript - What exactly does delete object.key delete in JS?
世界只因有你
世界只因有你 2017-06-28 09:28:09
0
3
974

delete What is deleted?

Why do I print first and then delete, but the result is that the object with this attribute has been deleted? Please help me, guys~~

var a = {love: 12, height: 10}
console.log(a) // 结果是 a = {height: 10}   为什么啊~~~
delete a.love;

It is obviously printed first and then deleted, so strange

世界只因有你
世界只因有你

reply all(3)
刘奇

Please note that when it is not expanded, it is {love: 12, height: 10}. After it is expanded, it is less, because when it is clicked, it displays the reference at that time. The simplest way to understand it is that you can use the console Add a debugger at the end

習慣沉默


When you click the arrow to view details, it will be re-evaluated.

黄舟

The object is a reference type value. It is correct that your console.log() outputs its information. However, after delete, the value of a in the heap has changed. When you click it, what is actually displayed is the heap. actual value.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template