Jump to content

Recommended Posts

Posted

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?

Posted

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.)

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...