2

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!

1
  • Do you want null as in your description or "" (empty string) as in your code sample? Commented Nov 17, 2011 at 5:20

3 Answers 3

8

You'd do it like this in JavaScript:

for(var p in adminID)
    if(adminID.hasOwnProperty(p))
        adminID[p] = '';
Sign up to request clarification or add additional context in comments.

Comments

3

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] = ""}

3 Comments

Thanks! Sorry i just realized i had implemented that in a javascript. How can I achieve the same in javascript.
I added a js version of my code as well. I think @mu's version is more robust.
Thank a lot, for the js version!
1
adminID.each_key {|key| adminID[key] = ''}

1 Comment

That's why I gave you an up-vote and went to the OP for some clarification. You answered what they asked rather than what they meant, or something like that. Hooray for confusion!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.