...

View Full Version : Refurring to Arrays using *.length



mentalhorse
12-30-2005, 07:18 PM
Hello. I am trying to make a number variable that takes the number of the amont of information in an array. 0bviously,

So here is my code involved.
// Below is the actualy array
function motherShip() {
var pain_in_butt = new Array();
for (index=0;index < number_of_rows;index++) {
pain_in_butt[index] = "<br />" }
}
// Bolded is where I try to refer to the .length of the pain_in_butt array
function theMath() {
var index_a = pain_in_butt.length;
for (index5=0;index5<index_a;index5++){
document.write("testing"); }
}
I am farely new to Javascript. I have tried putting document.pain_in_butt.length.

felgall
12-30-2005, 11:18 PM
If you define the array inside motherShip then it will be deleted when that function ends and is undefined after that. To keep it define it outside of the function like this:

// Below is the actualy array
var pain_in_butt = new Array();
function motherShip() {
for (index=0;index < number_of_rows;index++) {
pain_in_butt[index] = "<br />" }
}
// Bolded is where I try to refer to the .length of the pain_in_butt array
function theMath() {
var index_a = pain_in_butt.length;
for (index5=0;index5<index_a;index5++){
document.write("testing"); }
}

mentalhorse
12-31-2005, 01:01 AM
Thank you very much. I thought I tried that, but I guess not.
It now works.:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum