473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

undefined array

in javascript, is there a way to test if an array is undefined????
eg...
for (var x=0; x<10; x++){
if test_array[x] is undefined then x++
document.write(test_array[x])

if anyone can help, thanks... oh and if you can get the syntex right for me
thanks..

Jul 23 '05 #1
7 2327
OzThor wrote:
in javascript, is there a way to test if an array is undefined????

eg...
for (var x=0; x<10; x++){
if test_array[x] is undefined then x++
document.write(test_array[x])

if anyone can help, thanks... oh and if you can get the syntex right for me
thanks..


for (var x = 0; x < 10; x++) {
if (typeof test_array[x] == 'undefined') {
continue;
}

document.write(test_array[x]);
}

or

for (var x = 0; x < 10; x++) {
if (typeof test_array[x] != 'undefined') {
document.write(test_array[x]);
}
}

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #2
"OzThor" <ro*****@ncable.net.au> writes:
in javascript, is there a way to test if an array is undefined????
If it's undefined, then it isn't an array :)
eg...
for (var x=0; x<10; x++){
if test_array[x] is undefined then x++
document.write(test_array[x])


Ah, you want to know whether the array element is undefined.

for (var i=0;i<10;i++) {
if (typeof test_array[i] != "undefined") {
document.write(test_array[i]);
}
}

Good luck
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3
Vax
[...]
for (var x = 0; x < 10; x++) {
if (typeof test_array[x] != 'undefined') {
document.write(test_array[x]);
}
}


or

for(var x,y;x<10;x++)if(test_array[x]!=y)document.write(test_array[x])

(y is declared, but undefined)

v.
Jul 23 '05 #4
Vax
for(var y,x=0;x<10;x++)if(test_array[x]!=y)document.write(test_array[x])

(y is declared, but undefined)

v.

Jul 23 '05 #5
Vax wrote:
for(var
y,x=0;x<10;x++)if(test_array[x]!=y)document.write(test_array[x])

(y is declared, but undefined)


Using the type-converting comparison - != - means that - null - values
will also be true in - if(test_array[x] != y) - and - null - values are
not undefined. Either a typeof test or the strict (non-type
converting) - !== - comparison are probably the only way to truly
identify undefined array members.

Richard.
Jul 23 '05 #6
Vax

Użytkownik "Richard Cornford" <Ri*****@litotes.demon.co.uk> napisał w
wiadomo¶ci news:c8*******************@news.demon.co.uk...
Vax wrote:
for(var
y,x=0;x<10;x++)if(test_array[x]!=y)document.write(test_array[x])

(y is declared, but undefined)


Using the type-converting comparison - != - means that - null - values
will also be true in - if(test_array[x] != y) - and - null - values are
not undefined.


yes, but try:
javascript:x=null;alert(x==undefined)
javascript:var x=0;alert(x==undefined)
javascript:var x=false;alert(x==undefined)

problem is only(?) with "null"...

v.
Jul 23 '05 #7
Vax wrote:
"Richard Cornford" wrote:
Vax wrote:
for(var
y,x=0;x<10;x++)if(test_array[x]!=y)document.write(test_array[x])

(y is declared, but undefined)


Using the type-converting comparison - != - means that - null -
values will also be true in - if(test_array[x] != y) - and - null -
values are not undefined.


yes, but try:
javascript:x=null;alert(x==undefined)
javascript:var x=0;alert(x==undefined)
javascript:var x=false;alert(x==undefined)

problem is only(?) with "null"...


That is what I said, but - null - and - undefined - are still distinct.

Richard.
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lawrence | last post by:
I just switched error_reporting to ALL so I could debug my site. I got a huge page full of errors. One of the most common was that in my arrays I'm using undefined offsets and indexes. These still...
8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
1
by: Chris | last post by:
How do I stop displaying "undefined" when using the code below. The problem occurs as I want to display 5 items per page using setInterval but this causes 'mycars' to reach a value that doesn't...
19
by: Sharath A.V | last post by:
I had an argument with someone on wheather this piece of code can invoke undefined bahaviour. I think it does not invoke any undefined behaviour since there is sufficient memory space of 9...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
7
by: deepak | last post by:
Using 'char' as an array index is an undefined behavior?
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
3
by: gsuns82 | last post by:
HI all, I tried to read an array from an external javascript file called read.js,The array was declared & as well as defined with some values inside the <script> tag of a html file. For an...
5
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.