Frustrating...

T

Trevor

Why does alert(data[3]); work fine while var subject = data[3];
give me the error, "Error: data has no properties"?

for (i = 0; i < (data.length); i++) {
alert(data[3]); //this works fine!
var subject = data[3]; //this gives error!
var sender = data[4];
var date = data[5];
}

Thanks for your help.

Trevor
 
T

Thomas 'PointedEars' Lahn

Trevor said:
Why does alert(data[3]); work fine while var subject = data[3];
give me the error, "Error: data has no properties"?

for (i = 0; i < (data.length); i++) {


The inner parantheses are redundant, and

for (var i = 0, len = data.length; i < len; i++)
{

is safer and more efficient. And since order does not seem to matter,
the following is even more efficient:

for (var i = data.length; i--;)
{
alert(data[3]); //this works fine!
var subject = data[3]; //this gives error!
var sender = data[4];
var date = data[5];
}


That depends on your data. Literally.

However, I rather think you did not locate the actual error properly.


PointedEars

P.S.: Do not use the tab character to indent (posted) source code.

P.P.S.: Do not misuse the Subject header for expressing your feelings;
Use it to describe the subject of your posting, because the
Subject header is the first thing anyone sees of your posting,
and it influences his/her decision to read or not to read the
posting.
 
T

Thomas 'PointedEars' Lahn

Ian said:
Just out of curiosity, is there any performance benefit in using --i?

Generally, some say so. Specifically, there is none here as you want
evaluation of `i' as continue-condition _before_ its value is decreased.
Using `--i' here instead would force you to compare `--i > -1' and the
like to achieve the same, while you do not need to with `i--' as `0'
evaluates to `false' in (this) boolean expression(s) already.

Please provide attribution of quoted material; your Mozilla includes
that line automagically for a reason.


PointedEars
 
R

Riccardo from Castle

Thomas said:
Trevor wrote:
[snip]
for (i = 0; i < (data.length); i++) {

The inner parantheses are redundant, and

for (var i = 0, len = data.length; i < len; i++)
{

is safer and more efficient.

Why is it *safer* ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top