471,119 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

Associate array of arrays

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

Feb 22 '07 #1
5 2049
On Feb 22, 3:03 pm, "M. Fisher" <mcfishe...@gmail.comwrote:
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.

Feb 22 '07 #2
On Feb 22, 2:03 pm, "M. Fisher" <mcfishe...@gmail.comwrote:
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[i].length; j < ll; j ++ ) {
// send each number/value to doSomething
doSomething(arr[i][j]);
}
}
};

Or something like this?

var loopThrough = function () {
for ( var i in SDET_Lab130 ) {
for ( var j = 0, l = arr[i].length; j < l; j ++ ) {
// send each array of values to doSomething
doSomething(SDET_Lab130[i][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 :)
--
Isaac Z. Schlueter
http://isaacschlueter.com

Feb 22 '07 #3
Isaac Schlueter wrote:
On Feb 22, 2:03 pm, "M. Fisher" <mcfishe...@gmail.comwrote:
>>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]...
>>Now first off is this legal?

Yes, but this is better:

var SDET_Lab130 = {
'SDET' : [
[0,400,7,24431,25179,24919,1.09,base],
Unless base (the last entry in the array) is a variable, I would suggest
the following:

SDET_Lab130['SDET'][0] = [0,400,7,24431,25179,24919,1.09,"base"];

Mick

Feb 23 '07 #4
On Feb 22, 3:03 pm, "M. Fisher" <mcfishe...@gmail.comwrote:
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.

Feb 23 '07 #5
On Feb 23, 11:33 am, "M. Fisher" <mcfishe...@gmail.comwrote:
On Feb 22, 3:03 pm, "M. Fisher" <mcfishe...@gmail.comwrote:
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.

Feb 23 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Robert Oschler | last post: by
21 posts views Thread by yeti349 | last post: by
104 posts views Thread by Leszek | last post: by
24 posts views Thread by Michael | last post: by
57 posts views Thread by buuuuuum | last post: by
17 posts views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.