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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

undefined arrays

Status
Not open for further replies.

bentleykf

Programmer
Apr 29, 2002
59
0
0
AU
is there any other way of testing if an array element has no value other than using this kind of if-then statement

if (tempImageArray != undefined) {....}

i'm asking because the undefined method of testing this does not work in internet explorer on a mac.
 
lol, dont worry, i've solved my own problem again
duh...

if (tempImageArray[messageLoop]) {...}
 
To check if a value for an array has been set or not you should check if the element equals null:
<script>
var arrValues = new Array(7);
alert(arrValues[2]==null);
alert(arrValues[200]==null);
//checking an element at 200 does not change the array's length
alert(arrValues.length);
arrValues[200]=&quot;hello&quot;;
alert(arrValues.length);
alert(arrValues[200]==null);
</script>

To remove an element you can set it to null allthough this will not change the length of an Array in javascript.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top