Reputation: 3341
It's a simple question i have, I have a javascript object which is declared like this -
adminID = {"Name": "","AdminId": ""}
At a later point in the code i assign it some values -
adminID = {"Name": "xyzabc","AdminId": "123123"}
Now, how can i assign the values back to null so my object looks like
adminID = {"Name": "","AdminId": ""}
Is there a smarter way to do it or should i specify all the keys to null individually.
Cheers!
Upvotes: 2
Views: 6002
Reputation: 434585
You'd do it like this in JavaScript:
for(var p in adminID)
if(adminID.hasOwnProperty(p))
adminID[p] = '';
Upvotes: 8
Reputation: 5760
Ruby version
Here is one way
adminID.each {|k,v| adminID[k] = ""}
Here is another
adminID.keys.each {|k| adminID[k] = ""}
Javascript version
for(var i in adminID) { adminID[i] = ""}
Upvotes: 3