SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Queanbeyan
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript property names

    Hello,

    I'd like to find out if it is possible to assign object properties in javascript without knowing in advance what the name of the property will be. For example, in PHP you would do the same like this:

    PHP Code:
    $myobject->{$propertyName} = 'some data'
    Any help would be greatly appreciated.

    Wazza

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Using array notation:
    Code:
    myobject[propertyName] = 'some data';
    Often done with for...in loops:
    Code:
    for (var prop in obj) {
      obj[prop] = 'some value';
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •