verdure
verdure

Reputation: 3341

Declared javascript object set to null values

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

Answers (3)

mu is too short
mu is too short

Reputation: 434585

You'd do it like this in JavaScript:

for(var p in adminID)
    if(adminID.hasOwnProperty(p))
        adminID[p] = '';

Upvotes: 8

Moiz Raja
Moiz Raja

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

Dark Castle
Dark Castle

Reputation: 1299

adminID.each_key {|key| adminID[key] = ''}

Upvotes: 1

Related Questions