1
Well, I’m having some problems with the following code snippet:
alert(lineOut[i].trim() + " - - " + lineOut[i + 1].trim());
Uncaught Typeerror: Cannot read Property 'Trim' of Undefined(...)
The array lineOut
is a dynamically populated array, which at the time of execution of the above passage has the following values:
lineOut = ["6", "Comentario"];
Can someone give me a clue as to why this problem is happening?
How much is it worth
i
at the time of execution?– Emoon
That code is running within a cycle
for
? I see a risk ofi + 1
be greater than the index of the last element of the array and giveundefined
because of this. As @Emoon asked, what is the value ofi
and what is the value oflineOut.length
when this error occurs?– Sergio
@Emoon
for(var i = 0; i<lineOut.length; i++)
this is the header of my loop.– user42676
@Sergio
i = 0
andlineOut.length = 2
. But I’m probably overflowing the array index. I’m going to develop another logic to solve this problem. Thank you very much for the comment.– user42676