Link to home
Start Free TrialLog in
Avatar of kevbob650
kevbob650Flag for United States of America

asked on

Javascript Loop Issue

Using NodeJS.oracle, hence the use of javascript for my loop, but can't use jquery....
I have a record set from an Oracle query that returns twenty columns, one of which is "ticket".
I need to loop thru the results, and for every 30 records, push the value of "ticket" into a separate array. So I would end up with:
ticketArray1 = '1', '2', '3', ...... '30'
ticketArray2 = '31', '32', '33' ..... '60'
ticketArray3......

so I loop thru the query results and pus the results into a mainArray, that works fine

then I need to loop thru the mianArray and populate the ticket arrays. I can figure out how to get the value from the first 30 but I'm lost on getting values thereafter and populating separate arrays.
Thanks in advance for any assistance.
Avatar of Phil Phillips
Phil Phillips
Flag of United States of America image

I think I know what you're getting at, but I'm not 100% sure.  Could you post what you have so far for the first 30?  I should be able to build off of that.
Here's a fiddle that divides an array of 100 items into groups of 30.

http://jsfiddle.net/tommyBoy/nwtbwxrz/
Avatar of kevbob650

ASKER

Still confused, this is what I have, but getting an error saying "arrTicketList[arrTicketList.length] is not defined"
This is the result set of an Oracle query, 20 columns, I need column 4 for example.  See attached code example, I wasn't able to show code with braced "i" values??
Looks like your code didn't attach.

Though, "arrTicketList[arrTicketList.length]" won't work because arrays start at 0.  So, the last element of an array would be at "arrTicketList.length - 1"
Let me try the attachment again, not sure what happened, never attached a file before but it wouldn't let me submit the file since it had brackets with an iterator, go figure.
code-example.txt
I updated my jsFiddle to include a multidimensional array with twenty columns (represents your Oracle return). I extract the fourth column value into groups of five. I used your variable names where appropriate.

http://jsfiddle.net/jg17b533/5/
Thanks TomBeck,
We're getting closer!  So what your code does is uses a list but I need to create a series of arrays that I can loop thru on further steps  I will loop thru each new array and call a nodeJs function for each value(scary). Hence I was trying to develop a series of arrays like:
arrTicketList[0] = ['tkt1',' tk2',' tk3'. , etc...]
arrTicketList[1] = ['tkt1',' tk2',' tk3'. , etc...]
arrTicketList[2] = ['tkt1',' tk2',' tk3'. , etc...]
etc..
But I also tried using the 'i' value but I get the same error, arrTicketList is not defined?
ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for all of the posts, very helpful
You're welcome. Thanks for the points.