0

help!!! how clear the all object?

help!!! how clear the all object? for example: var x = { x:1 y:2 } //need to completely clear the object, regardless of the names of the variables in the object. and get an empty object as output. how to do it?

10th Apr 2022, 4:09 PM
Alexander Sokolov
Alexander Sokolov - avatar
7 ответов
+ 3
var x = { x:1, y:2 } console.log("before reset ") ; for( let i in x ) console.log(i+" "+x[i]); x={} console.log("after reset") ; for( let i in x ) console.log(i+" "+x[i]);
10th Apr 2022, 4:29 PM
Jayakrishna 🇮🇳
0
x = {}
10th Apr 2022, 4:15 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 does this really work? Do you have any evidence to support your answer to my question?
10th Apr 2022, 4:16 PM
Alexander Sokolov
Alexander Sokolov - avatar
0
but does this method actually clear the object and not replace it?Jayakrishna🇮🇳
10th Apr 2022, 4:33 PM
Alexander Sokolov
Alexander Sokolov - avatar
0
Not understood.. Your question is clear the object.. Replacing empty object is clear the contents in simple way..
10th Apr 2022, 4:38 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 are there harder ways? if there is, kindly provide them to me. Thank you
10th Apr 2022, 4:39 PM
Alexander Sokolov
Alexander Sokolov - avatar
0
You can use 'delete' also var x = { x:1, y:2 } console.log("before reset ") ; for( let i in x ) { console.log(i+" "+x[i]); delete x[i] } //x={} console.log("after reset") ; for( let i in x) console.log(i+" "+x[i]); // first one ({}) leaves a task for garbage collection but this deletes there itself.. hope it helps....
10th Apr 2022, 4:41 PM
Jayakrishna 🇮🇳