Im receiving json data that is aggregated by numerical indexes. When Im in my forloop, for example, the index might start at 1, which means in my forloop an error would occur because 0 doesnt exist. How do I check if a numerical index exists in the javascript array?
closed as not a real question by JE SUIS CHARLIE, Alp, Stewie, WATTO Studios, Roman C Jun 22 '13 at 12:21It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question. |
|
|
|||||
|
You should be able to use
Which will loop over each key item in data if the indexes aren't contiguous. |
|||
|
If what you are actually describing is an Javascript
Output
On jsfiddle Ok, now you have a sparsely populated array and want to use a Javascript
Ouput
On jsfiddle Alternatively, you can use Javascript
Output
On jsfiddle |
|||||
|
You can check to see if the index is
If you're looping like this, you're going to have a bad time because your array does not start with a 0-based index.
The pattern above works for most arrays, but it seems like your array is not like most arrays!
|
||||
|
undefined
, right? – acdcjunior Jun 21 '13 at 22:49Array.length
is broken) without you showing us any code. :/ – Xotic750 Jun 21 '13 at 23:31