473,382 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 2163
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert Oschler | last post by:
With PHP 4, is there a way to convert an associative array to an object? For example, suppose I have the following arrays inside a nested associative array ($nestedAA): $AA1 = 'fieldValue1'; ...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
57
by: buuuuuum | last post by:
why array can't be assigned, like structs?
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
1
by: chiefychf | last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge...
2
by: forrestarrow | last post by:
Hi everyone, I used STL map in my code and I am wondering is the associate data automatically initialized or not. The reason I am asking is that I have two arrays of data, and the first array is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.