There are other ways to define your data. You can use both array-literal notation and object-literal notation. You can even use a combination of both or even other data types to create more complex data structures.
In your first section, the "notify array" is really being used like an object with array notation (the square brackets as subscripts). When you use object-literal notation, you replace the square brackets with curly braces and use named values instead of indices. This is also called a hashtable. In this example, I'm creating an object with arrays for properties:
var notify1 = {
code: [],
type: [],
reason: [],
solution: [],
timeout: []
};
You can access the properties of the new "notify object" like this (for example):
notify1.code[0]; // object notation
or
notify1["code"][0]; // array notation
I could also do this to create an array of objects:
var notify2 = [
{code: "", type: "", reason: "", solution: "", timeout: 0},
{code: "", type: "", reason: "", solution: "", timeout: 0},
{code: "", type: "", reason: "", solution: "", timeout: 0}
];
You could access this array of objects like this:
notify2[0].code
or
notify2[0]["code"]
... it's up to you. For more information, take a look at JSON (JavaScript Object Notation): http://www.json.org/
Regarding your other question, JavaScript arrays are usually sparse (unless defined using the new Array() syntax... depending on the browser). Any locations in the array that are not initialized are set to undefined. So you can do this:
var test1 = {
code: []
};
test1.code[5] = "qwerty";
test1.code[7] = "asdfgh";
alert( test1.code[5] ); //displays "qwerty"
alert( test1.code[2] ); //displays "undefined"
or
var test2 = {
code: [,,,,,"qwerty",,"asdfgh"]
};
alert( test2.code[5] ); //displays "qwerty"
alert( test2.code[2] ); //displays "undefined"