Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    [jQuery] syntax question

    Hi
    Im fairly new to js and find I need to use the jQuery library. I am struggling to understand this code:
    Code:
    <script id="source" language="javascript" type="text/javascript">
    $(function () {
        var datasets = {
            "usa": {
                label: "USA",
                data: [[1988, 483994], [1989, 479060], [1990, 457648], [1991, 401949], [1992, 424705], [1993, 402375], [1994, 377867], [1995, 357382], [1996, 337946], [1997, 336185], [1998, 328611], [1999, 329421], [2000, 342172], [2001, 344932], [2002, 387303], [2003, 440813], [2004, 480451], [2005, 504638], [2006, 528692]]
            },
    First off, what is the 'datasets' data structure called?
    Secondly, is there a way that I can use a function to populate the 'data' array, like so:
    Code:
    var datasets = {
        "usa": {
            label: "USA",
            data: xmlToArray('WGTPRICE')
     },
    TIA,
    Ed

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    the code is simply constructing a javascript object...all objects in javascript are associative arrays so you can simply add a key-value pair anytime....the notation you see there is called JSON (javascript object notation) which is sorta short form to create objects.

    and, yes you can use a function to set the value of an attribute in javascript
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Posting Permissions

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