sandig199 Posted August 8, 2018 Posted August 8, 2018 I have an array of values, but I need to be able to "stop" the array when a value is "nothing" and then continue to start a new array with the next series of values. Example: [value1,value2,value3,value4,value5,value6,value7,value8,value9] if value1,value2 have a value then Array1 = [value1,value2] if value3 == "", then the array stops. And start a new array picking up where we left off Array2 = [value4] if value5 == "", then the array stops. and pick up where we left off Array3 = [value6,value7,value8,value9] Is this possible? Quote
Dan Korn Posted August 8, 2018 Posted August 8, 2018 Sure, something like this: var arr = [1,2,3,,5,6,,8,9]; var result = [[]]; for (var i in arr) { var el = arr[i]; if (el) result[result.length-1].push(el); else result.push([]); } return result.join('\n'); Where the result is an array of arrays. By the way, this kind of purely generic JavaScript question (with nothing specific to FusionPro) can be asked almost anywhere on the web, such as Stack Overflow: https://stackoverflow.com/questions/tagged/javascript Or just type your question into Google. (Though in this particular case, my Google-fu wasn't good enough to get a result.) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.