Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Thanked 0 Times in 0 Posts

    Question How to create this object in javascript?

    I'm writing a script in javascript(actually a chrome extension) and I need an object that I can write to it like this(sorry, don't know how to explain it better) and then I convert it to string with format of json.

    id[129].weekDay[6].hour[23] = 0
    Here, id is an array, that each element in it contain another array(weeksDay) and in that array each contain another array(hour).
    The id indices are unlimited, for weekDay 7 and hour 24.

    I searched in google but i couldn't find what I wanted. Actually don't know the best keyword to search.(objects in arrays?)

    I don't know what exactly it is called, I can write it's declaration in VB.NET if that helps you.

  2. #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,947 Times in 4,908 Posts

    // constructor for a DAY object:
    function DAY( )
        this.hour = [];
        this.minute = [];
        this.second = [];
    // constructor for a WEEK object:
    function WEEK( start, days )
        this.startDate = start;
        this.weekDay = days == null ? [] : days;
    var id = []; // an array of WEEK objects
    var d = new DAY( );
    d.hour[16] = "School lets out";
    var w = new WEEK( new Date(2011,6,16) ); // notice only one argument supplied
    w.weekDay[6] = d;
    id[129] = w;
    // an then:
    alert( id[129].weekDay[6].hour[16] ); // would alert "School lets out"
    Last edited by Old Pedant; 05-27-2011 at 09:54 PM.
    Be yourself. No one else is as qualified.


Tags for this Thread

Posting Permissions

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