This does not work:
var i ; for( i in items; i++; ) { delete items[i] ; }
It creates a for-loop with the initialization code i in items (which btw evaluates to false , since there is no "undefined" enter items , but it does not matter), and the condition is i++ and no update code. However, i++ evaluates the falsity of NaN , so your loop is immediately interrupted. And without a second semicolon, it's even like a SyntaxError.
Instead, you want a for-in-loop :
for (var i in items) { delete items[i]; }
Btw, items.clean = true; will create a new property again, so the object will not really be "clean" :-)
I was wondering if there is a shorter way for this. For example, array cleaning can be done as follows
No. You must combine all the properties and remove them.
Bergi source share