Loading ...
Sorry, an error occurred while loading the content.

Re: Object Literal Key

Expand Messages
  • santini.alberto
    ... If I understand your question, maybe the lines below could help. myVar = key1 ; someValue = 42; objLit[myVar] = someValue; objLit[ key1 ] // it contains
    Message 1 of 2 , Sep 4, 2008
    • 0 Attachment
      --- In ydn-javascript@yahoogroups.com, "oglesys" <oglesys@...> wrote:
      >
      > How can I create an object literal, which contains a dyamically
      > changing key ?
      >
      > i.e.
      >
      > myVar = userInput;
      >
      > ...
      >
      > objLit = { myVar: someValue };

      If I understand your question, maybe the lines below could help.

      myVar = "key1";
      someValue = 42;

      objLit[myVar] = someValue;
      objLit["key1"] // it contains 42
      objLit.key1 // it contains 42


      Regards,
      Alberto Santini
    Your message has been successfully submitted and would be delivered to recipients shortly.