kevbob650
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.
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.
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/
http://jsfiddle.net/tommyBoy/nwtbwxrz/
ASKER
Still confused, this is what I have, but getting an error saying "arrTicketList[arrTicketLi st.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??
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[arrTicketLi st.length] " won't work because arrays start at 0. So, the last element of an array would be at "arrTicketList.length - 1"
Though, "arrTicketList[arrTicketLi
ASKER
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
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/
http://jsfiddle.net/jg17b533/5/
ASKER
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for all of the posts, very helpful
You're welcome. Thanks for the points.