Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-27-2011, 01:05 PM   PM User | #1
alFReD-NSH
New to the CF scene

 
Join Date: May 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
alFReD-NSH is an unknown quantity at this point
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.

Code:
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.
alFReD-NSH is offline   Reply With Quote
Old 05-27-2011, 08:50 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Example:

Code:
// 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"
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 05-27-2011 at 08:54 PM..
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Tags
array, chrome extension, javascript, json, object

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:51 AM.


Advertisement
Log in to turn off these ads.