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!

How do I test for "UNDEFINED" for an array? 1

Status
Not open for further replies.

computerwhiz

Programmer
May 1, 2002
28
US
I have 17 forms that my users will be filling out. and if they decide to go back to one of the forms I want to be able to fill in their old values. But if there were no values there in the first place it fills in the text input value area with "undefined". How do I test my data array to see if it has value or if it is "undefined" so it doesn't fill in the areas with "undefined"?
 
maybe u could something like
var count = 0;
while (count < max) {
if (thearray[count] == &quot;undefined&quot;) {//do something}
count++;
}
someone knowledge ends where
someone else knowledge starts
 
undefined is NOT a string value, but a separate data type, so NEVERSLEEP's solution won't work. However, if you use that example with this modification:

if ((thearray[count]+'') == &quot;undefined&quot;) {//do something}

it'll convert the undefined value to a string, and make it &quot;undefined&quot;, which you can test for as a string. In my experience, testing for the undefined data type doesn't work consistently in all browsers, so I always do this kind of conversion before testing.
 
I was having a blonde moment and figured out that I should just do it this way

if (DataArray[count] != null){//assign value to form element)}

thanks for your input though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top