Associate array of arrays

M

M. Fisher

Pardon my ignorance here...

I have created arrays such as:
var SDET_Lab130= new Array();
SDET_Lab130['SDET'] = new Array();
SDET_Lab130['SDET'][0] = [0,400,7,24431,25179,24919,1.09,base];
SDET_Lab130['SDET'][1] = [1,400,7,27729,28031,27877,0.34,11.87,rate
Improved];
SDET_Lab130['SDET'][2] = [0,450,7,24691,25194,24966,0.75,base];
SDET_Lab130['SDET'][3] = [1,450,7,27598,28090,27860,0.60,11.59,rate
Improved];
SDET_Lab130['SDET'][4] = [0,500,7,24725,25171,24967,0.74,base];
SDET_Lab130['SDET'][5] = [1,500,7,27556,27941,27795,0.52,11.32,rate
Improved];

Now first off is this legal? If so I am having trouble accessing the
elements of the array. Basically I have a function which takes in the
hash string, then I want to loop through using two nested loops to get
all the elements of all the arrays for a given hash string.

Seems that to go through an associative array you need a loop as such
first
for (i in uniqueID[selected]) {

I guess if that is the case how to I drill down further from here?

Thanks a lot in advance. Any help is greatly appreciated.
Marc
 
M

M. Fisher

Pardon my ignorance here...

I have created arrays such as:
var SDET_Lab130= new Array();
SDET_Lab130['SDET'] = new Array();
SDET_Lab130['SDET'][0] = [0,400,7,24431,25179,24919,1.09,base];
SDET_Lab130['SDET'][1] = [1,400,7,27729,28031,27877,0.34,11.87,rate
Improved];
SDET_Lab130['SDET'][2] = [0,450,7,24691,25194,24966,0.75,base];
SDET_Lab130['SDET'][3] = [1,450,7,27598,28090,27860,0.60,11.59,rate
Improved];
SDET_Lab130['SDET'][4] = [0,500,7,24725,25171,24967,0.74,base];
SDET_Lab130['SDET'][5] = [1,500,7,27556,27941,27795,0.52,11.32,rate
Improved];

Now first off is this legal? If so I am having trouble accessing the
elements of the array. Basically I have a function which takes in the
hash string, then I want to loop through using two nested loops to get
all the elements of all the arrays for a given hash string.

Seems that to go through an associative array you need a loop as such
first
for (i in uniqueID[selected]) {

I guess if that is the case how to I drill down further from here?

Thanks a lot in advance. Any help is greatly appreciated.
Marc


I don't think this matters, but throw it in too. The arrays are
declared in data.js which I include in the html file. And the function
to loop through is in dynmodule.js also included in a different file,
so the data resides in a file outside of the one with the function.
 
I

Isaac Schlueter

Pardon my ignorance here...

I have created arrays such as:
var SDET_Lab130= new Array();
SDET_Lab130['SDET'] = new Array();
SDET_Lab130['SDET'][0] = [0,400,7,24431,25179,24919,1.09,base];
SDET_Lab130['SDET'][1] = [1,400,7,27729,28031,27877,0.34,11.87,rate
Improved];
SDET_Lab130['SDET'][2] = [0,450,7,24691,25194,24966,0.75,base];
SDET_Lab130['SDET'][3] = [1,450,7,27598,28090,27860,0.60,11.59,rate
Improved];
SDET_Lab130['SDET'][4] = [0,500,7,24725,25171,24967,0.74,base];
SDET_Lab130['SDET'][5] = [1,500,7,27556,27941,27795,0.52,11.32,rate
Improved];

Now first off is this legal?

Yes, but this is better:

var SDET_Lab130 = {
'SDET' : [
[0,400,7,24431,25179,24919,1.09,base],
[1,400,7,27729,28031,27877,0.34,11.87,rateImproved],
[0,450,7,24691,25194,24966,0.75,base],
[1,450,7,27598,28090,27860,0.60,11.59,rateImproved],
[0,500,7,24725,25171,24967,0.74,base],
[1,500,7,27556,27941,27795,0.52,11.32,rateImproved]
]
};
If so I am having trouble accessing the
elements of the array. Basically I have a function which takes in the
hash string, then I want to loop through using two nested loops to get
all the elements of all the arrays for a given hash string.

Something like this?

var loopThrough = function (key) {
var arr = SDET_Lab130[key];
for ( var i = 0, l = arr.length; i < l; i ++ ) {
for ( var j = 0, ll = arr.length; j < ll; j ++ ) {
// send each number/value to doSomething
doSomething(arr[j]);
}
}
};

Or something like this?

var loopThrough = function () {
for ( var i in SDET_Lab130 ) {
for ( var j = 0, l = arr.length; j < l; j ++ ) {
// send each array of values to doSomething
doSomething(SDET_Lab130[j]);
}
}
};

Seems that to go through an associative array you need a loop as such
first for (i in uniqueID[selected]) {

You'll probably be less confused if you stop using the term
"Associative array. In Javascript, there are Objects, and there are
Arrays. Arrays are numeric ordered lists; Objects are hash tables.
Arrays use [], Objects use {} (though Objects can use the myObj['key']
form, which is just there because Javascript likes to be confusing ;)
For/in is for Objects, and for/iterate is for arrays.
It's easiest and less confusing to use them for what they're for.

I don't think this matters, but throw it in too. The arrays are
declared in data.js which I include in the html file. And the function
to loop through is in dynmodule.js also included in a different file,
so the data resides in a file outside of the one with the function.

You're right--it doesn't matter. As long as data.js appears before
the code that uses the object, you should be fine.

Cheers :)
 
M

M. Fisher

Pardon my ignorance here...

I have created arrays such as:
var SDET_Lab130= new Array();
SDET_Lab130['SDET'] = new Array();
SDET_Lab130['SDET'][0] = [0,400,7,24431,25179,24919,1.09,base];
SDET_Lab130['SDET'][1] = [1,400,7,27729,28031,27877,0.34,11.87,rate
Improved];
SDET_Lab130['SDET'][2] = [0,450,7,24691,25194,24966,0.75,base];
SDET_Lab130['SDET'][3] = [1,450,7,27598,28090,27860,0.60,11.59,rate
Improved];
SDET_Lab130['SDET'][4] = [0,500,7,24725,25171,24967,0.74,base];
SDET_Lab130['SDET'][5] = [1,500,7,27556,27941,27795,0.52,11.32,rate
Improved];

Now first off is this legal? If so I am having trouble accessing the
elements of the array. Basically I have a function which takes in the
hash string, then I want to loop through using two nested loops to get
all the elements of all the arrays for a given hash string.

Seems that to go through an associative array you need a loop as such
first
for (i in uniqueID[selected]) {

I guess if that is the case how to I drill down further from here?

Thanks a lot in advance. Any help is greatly appreciated.
Marc


Thanks for the help so far. If I want to expand this would the correct
syntax be:
var SDET_Lab130 = {
'SDET_Load1' : [
[0,400,7,24431,25179,24919,1.09,base],
[1,400,7,27729,28031,27877,0.34,11.87,rateImproved],
[0,450,7,24691,25194,24966,0.75,base],
[1,450,7,27598,28090,27860,0.60,11.59,rateImproved],
[0,500,7,24725,25171,24967,0.74,base],
[1,500,7,27556,27941,27795,0.52,11.32,rateImproved]
],
'SDET_Load2' : [
[0,400,7,24431,25179,24919,1.09,base],
[1,400,7,27729,28031,27877,0.34,11.87,rateImproved],
[0,450,7,24691,25194,24966,0.75,base],
[1,450,7,27598,28090,27860,0.60,11.59,rateImproved],
[0,500,7,24725,25171,24967,0.74,base],
[1,500,7,27556,27941,27795,0.52,11.32,rateImproved]
],
...
};

I have tried this and inside my function now where I do
var arr = SDET_Lab130[key];
and then try to access the length for arr, I get the error no property
defined. Also I have 11 'Load' identifiers but doing
SDET_Lab130.length gives me 19, so I am guessing that means my syntax
I am using is not right. Sorry again for the ignorance.
 
M

M. Fisher

Pardon my ignorance here...
I have created arrays such as:
var SDET_Lab130= new Array();
SDET_Lab130['SDET'] = new Array();
SDET_Lab130['SDET'][0] = [0,400,7,24431,25179,24919,1.09,base];
SDET_Lab130['SDET'][1] = [1,400,7,27729,28031,27877,0.34,11.87,rate
Improved];
SDET_Lab130['SDET'][2] = [0,450,7,24691,25194,24966,0.75,base];
SDET_Lab130['SDET'][3] = [1,450,7,27598,28090,27860,0.60,11.59,rate
Improved];
SDET_Lab130['SDET'][4] = [0,500,7,24725,25171,24967,0.74,base];
SDET_Lab130['SDET'][5] = [1,500,7,27556,27941,27795,0.52,11.32,rate
Improved];
Now first off is this legal? If so I am having trouble accessing the
elements of the array. Basically I have a function which takes in the
hash string, then I want to loop through using two nested loops to get
all the elements of all the arrays for a given hash string.
Seems that to go through an associative array you need a loop as such
first
for (i in uniqueID[selected]) {
I guess if that is the case how to I drill down further from here?
Thanks a lot in advance. Any help is greatly appreciated.
Marc

Thanks for the help so far. If I want to expand this would the correct
syntax be:
var SDET_Lab130 = {
'SDET_Load1' : [
[0,400,7,24431,25179,24919,1.09,base],
[1,400,7,27729,28031,27877,0.34,11.87,rateImproved],
[0,450,7,24691,25194,24966,0.75,base],
[1,450,7,27598,28090,27860,0.60,11.59,rateImproved],
[0,500,7,24725,25171,24967,0.74,base],
[1,500,7,27556,27941,27795,0.52,11.32,rateImproved]
],
'SDET_Load2' : [
[0,400,7,24431,25179,24919,1.09,base],
[1,400,7,27729,28031,27877,0.34,11.87,rateImproved],
[0,450,7,24691,25194,24966,0.75,base],
[1,450,7,27598,28090,27860,0.60,11.59,rateImproved],
[0,500,7,24725,25171,24967,0.74,base],
[1,500,7,27556,27941,27795,0.52,11.32,rateImproved]
],
...

};

I have tried this and inside my function now where I do
var arr = SDET_Lab130[key];
and then try to access the length for arr, I get the error no property
defined. Also I have 11 'Load' identifiers but doing
SDET_Lab130.length gives me 19, so I am guessing that means my syntax
I am using is not right. Sorry again for the ignorance.

Sorry got this working now, compatibility issue in Mozilla was
actually causing my errors with insertRow and not feeding it -1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top