You are not logged in.

#1 2010-01-07 19:31:50

madeye
Member
From: Denmark
Registered: 2006-07-19
Posts: 331
Website

multidimensional array in jquery class/object

I'm trying to get into javascript and jquery for a hobby project of mine. Now I've used the last 4 hours trying to find a guide on how to create class objects that can contain the following information

Identification : id
Group : group
Persons : array(firstname : name, lastname : name)

Anyone know of a tutorial that can show me how to do this?

I found this page where I can see that an object can contain an array, but it doesn't state whether it is possible to use a multidimensional array.

And this page just describes the object with normal values.

Any pointers in the right direction are appreciated.


MadEye | Registered Linux user #167944 since 2000-02-28 | Homepage

Offline

#2 2010-01-08 01:17:35

wuischke
Member
From: Suisse Romande
Registered: 2007-01-06
Posts: 630

Re: multidimensional array in jquery class/object

There are no classes in JavaScript. It uses a different style of objects and what you found is indeed what you need.

Well, it might help to think about it as a dynamic, runtime-modifiable object system. An Object is not described by class, but by instructions for its creation.

Here you have your object. Note that you can use variables everywhere.

var id = 123;
var test = {"Identification": id,
"Group": "users",
"Persons": [{"firstname":"john", "lastname":"doe"},{"firstname":"jane","lastname":"doe"}]
}

This is identical to the following code. (The first one is a lot nicer, though.)

var id = 123;
var test = new Object();
test.Identification = id;
test["Group"] = "users;
test.Persons = new Array();
test.Persons.push({"lastname":"doe","lastname":"john"});
test.Persons.push({"lastname":"doe","lastname":"jane"});

As you can see, you can dynamically add new properties to an object. You can use both the dot-syntax (object.property) and the hash syntax (object["property"]) in JavaScript.

Offline

#3 2010-01-08 09:40:47

madeye
Member
From: Denmark
Registered: 2006-07-19
Posts: 331
Website

Re: multidimensional array in jquery class/object

Thanks wuischke

That's what I was looking for. It's a lot easier to understand when showed an example.

Ich wünsch dir noch 'nen schönen Tag!


MadEye | Registered Linux user #167944 since 2000-02-28 | Homepage

Offline

Board footer

Powered by FluxBB