Computing.Net > Forums > Web Development > lenght is null?

lenght is null?

Reply to Message Icon

Original Message
Name: darkhalf
Date: October 18, 2005 at 05:09:33 Pacific
Subject: lenght is null?
OS: xp
CPU/Ram: 1.5
Comment:

I must be missing something, but can someone tell me why this keeps giving me an error saying that length is null or not an object???

var redoIndex = new Array();
var currentRedo=0;

function analyzeResults()
{
if (redoIndex.length > 0)
{
redoIndex = null;
var redoIndex = new Array();
alert (redoIndex.length);
}
else
alert ("somethingelse");

}


Report Offensive Message For Removal

Response Number 1
Name: Michael J (by mjdamato)
Date: October 18, 2005 at 06:51:43 Pacific
Subject: lenght is null?
Reply: (edit)

Because when you declare redoIndex as an Array you are just defining the type of variable it is. Since you do not assign any values to it is still a null object. So you get that error when trying to determine the lenght of that null object in your comparison.

Change:

if (redoIndex.length > 0)

To:

if (redoIndex != null)

Michael J


Report Offensive Follow Up For Removal

Response Number 2
Name: darkhalf
Date: October 18, 2005 at 07:47:58 Pacific
Subject: lenght is null?
Reply: (edit)

actually that's not the problem... the error is here:

redoIndex = null;
-> var redoIndex = new Array();
alert (redoIndex.length);

removing the var makes everyone happy...


Report Offensive Follow Up For Removal

Response Number 3
Name: Michael J (by mjdamato)
Date: October 18, 2005 at 09:56:27 Pacific
Subject: lenght is null?
Reply: (edit)

Uh, no it isn't. I copied the code into a file and the error occures on this line:

--> if (redoIndex.length > 0)

I made the change as noted above and it works.

Michael J


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: lenght is null?

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software