Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get all array indices?

Status
Not open for further replies.

jagi

Programmer
Mar 13, 2005
48
US
Hi,

I have an object array to store all the text-boxes that have been changed. (cell-ids along with values)
The function looks like this:

function fnEditData(textObj) {
var parentTDCell = textObj.parentNode;
textValObj[parentTDCell.id] = textObj.value;
computePltTotals(textObj);
computeMktTotals(textObj);
}

I pass this textValObj[] to another page.
Now my question is, how can i retrieve all the indices of the array as a collection?

Can anyone help?

thanks.
 

Why do you need to access the array as a collection when you can access it as an array? The methods for accessing both are identical most of the time.

Incidentally, you are not storing the cell ids - you are storing a pointer to the cell element itself. Just in case you are having grief with that one ;o)

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
Actually I want to be able to access the indices in the array.
Can i do that?
 

If you mean that you want to be able to access any individual object within your array, the answer is yes. You would access it no differently on the page you are passing it to, as you would on the page it is declareed on.

Of course, this assumes that you are passing the array as an array, and not as a string or some other data type.

Dan


The answers you get are only as good as the information you give!

 
I have this object array:
var textValObj = new Array[10];
textValObj['abc_08/30/04'] = '30.0';
textValObj['xyz_09/01/04'] = '72.5';
...

How can I get all the string indices from the array textValObj?
(indices: 'abc_08/30/04', 'xyz_09/01/04')

Any ideas ?
 
To get an array of the "key" values, you can do this:
Code:
var keys=[];
for(key in textValObj){
  keys[keys.length]=key;
}

Adam

Pedro offers you his protection
 
BillyRayPreachersSon said:
Incidentally, you are not storing the cell ids - you are storing a pointer to the cell element itself.
I got confused by what you mean there, Dan. parentTDCell.id is a string, not an object. I don't understand how he's storing a pointer.

Adam

Pedro offers you his protection
 

Ah yes - good point Adam.

I was referring to the previous line of code, but it turns out I totally misread it. Thanks for clearing that one up.

Dan


The answers you get are only as good as the information you give!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top