www.webdeveloper.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2012
    Posts
    11

    Question Associative array

    Hello!

    I jsut have question about associative array:

    Code:
    var dataObject = {date:date, test:temp};
    Now I know "date" and "test" are the "IDs" of the values.
    Is it possible to make the IDs dynamic?

    Like:
    Code:
    var names = ["test1", "test2"];
    var dataObject1 = {date:date, names[0]:temp1};
    var dataObject2 = {date:date, names[1]:temp2};

  2. #2
    Join Date
    Mar 2011
    Posts
    64
    I did not get your point, but I guess what you want to do: a 2-d array..

    you can make array(date=>date, names=>array(0=>temp1, 1=>temp2))

    That way your array:names[0] and array:names[1] will print different values, but array:date will always be date

    Basically you stick an array into an array, just try to visualize it and you'll figure it out

  3. #3
    Join Date
    Dec 2005
    Location
    FL
    Posts
    6,967
    See if this make sense to you...
    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    <script type="text/javascript">
    
    var dataObject = {'date':'date', 'test':'temp'};
    alert(dataObject['date']+'\n'+dataObject['test']);
    
    dataObject['time'] = 'Time entry';
    dataObject['place'] = 'Place entry';
    
    var activity = 'Some Activity';
    var some_action = 'Do something';
    dataObject[activity] = some_action;
    
    var str = '';
    for (var i in dataObject) {
      str += i+' : '+dataObject[i]+'\n';
    }
    alert(str);
    </script>
    
    </head>
    <body>
    
    </body>
    </html>
    Last edited by JMRKER; 06-19-2012 at 11:10 AM.

  4. #4
    Join Date
    Apr 2012
    Posts
    11
    Thx!

    For more clearance:
    I will use amCharts and I have to define the ID of the dataobject what will be drawn on the chart.

    As I have more than one dynamic sorce for the chart I want to also handle the dataobject dynamic.

  5. #5
    Join Date
    Dec 2005
    Location
    FL
    Posts
    6,967

    Thumbs up

    Quote Originally Posted by schwa226 View Post
    Thx!

    For more clearance:
    I will use amCharts and I have to define the ID of the dataobject what will be drawn on the chart.

    As I have more than one dynamic sorce for the chart I want to also handle the dataobject dynamic.
    You're most welcome.
    Happy to help.
    Good Luck!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
HTML5 Development Center



Recent Articles