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
    Dec 2003
    Location
    Bahamas
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need Help w/Structures & formatting

    1) How does one creat an array of structures in JS? I cannot find any examples of structure e.g
    type custinfo {
    Name string
    Phone string
    ID long
    .
    .
    }

    arraynew(60) of custinfo


    2) How can I format an output field to be currency w/o having to write a routine
    Last edited by trsands; 12-29-2003 at 10:21 AM.

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What you'll need to look into is object literals. They've got a funky syntax, but they work slick as anything:
    Code:
    var myObj = {
        property : 'value',
        method : function () {
            (function definition)
        },
        calculatedValue : (formula)
    };
    Then, to create a myObj, you just need a loop:
    Code:
    var objArray = new Array();
    for (var i=0;i<60;i++) {
        objArray[i] = new myObj();
    }
    And then you'll have the array full of objects. Objects are much more powerful than structures. From your posted example, I'm guessing you're a ColdFusion developer -- objects are more like CFCs than regular old structures; however, they can be used just like structures in CF.

    The above object can be accessed from the above array like this:
    Code:
    objArray[20].property
    objArray[6].method()
    objArray[55].calculatedValue
    Enjoy!


  •  

    Posting Permissions

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