0

I've just go into developing apps through Titanium's Appcelerator and therefore this is my first experience with Javascript as well. Running into a confusing thing with regards to referencing array values and I was just hoping someone would be able to tell me what is going on.

Basically it boils down to while trying to iterate through a tableView, the following returns the correct values

tableView.data[i].rows[++j]

However this always return undefined

tableView.data[i].rows[j+1]

Can someone explain this to me?

EDIT: Here is the loop I'm talking about

for (i in tableView.data)
for (j in tableView.data[i].rows)
if ("undefined" !== typeof tableView.data[i].rows[j].children[1] && "undefined" !== typeof tableView.data[i].rows[j+1]) {
    console.debug("i: " + i + " j: " + j)
} else
    console.debug("undefined")
JonoCoetzee
  • 959
  • 2
  • 14
  • 29

1 Answers1

0

j+1 to move to the next should be written as (j+=1) or j++ or later increment after use ++j j+1 will always remain what j was initialized as plus one, so at some point there may be overun or endless looping.

  • That makes no sense... I want what j was initialised to plus one, I don't want to replace j with j plus one. And no there won't be an overrun or endless looping because they're in a "for i in" loop. – JonoCoetzee Jul 29 '13 at 07:37