Beginner-Help with parsing out multi select drop downs

Hi!
I am very new to Java Script and wondering if someone would be able to help me. I have columns F-K (target column numbers 5-10) that are each a multi select drop down field. So, there are multiple answers chosen in these cells. Only one of the columns will be used as a multi select per row. So, if column F has values in it then columns G-K will not have values in it for that row. I am in need of parsing out these multi select answers. So, if on cell F2 10 answers were chosen in this cell then there should be 10 rows of data (one answer per row with the other data copied down). I have the below code so far for column K (#10), but not sure how I get it to do the other columns.
Any help would be very much appreciated! Thank you!

function zoneparse(range) {
delimiter = "\n"
targetColumn = 10

var output2 = [];
for(var i=0, iLen=range.length; i<ilen; i++)="" {
="" var="" s="range[i][targetColumn].split(delimiter);"
="" for(var="" j="0," jlen="s.length;" j<jlen;="" j++)="" output1="[];" k="0," klen="range[0].length;" k<klen;="" k++)="" if(k="=" targetcolumn)="" output1.push(s[j]);
="" }="" else="" output1.push(range[i][k]);
="" }
="" output2.push(output1);
="" return="" output2;
}

Welcome, adray.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).


I do not know if you meant to add extra characters in your code to help format the code, but it is now completely un-understandable. So, I suggest you edit your post to include the correct formatting.

Hi adray and welcome!
I’m still a bit unclear on the description of your problem, do you have more examples of data in tables as you mentioned?

Also, a handy tool when pasting code is to check if your code is having the conventional format or not. You can use an online tool like the one here.
Some of the code editors like VsCode usually have some shortcuts like Ctrl + K + F that would activate the beautifier for you.

Doing the above would help us detect the issue and solve it easier as Shaun also mentioned above.

Good luck :call_me_hand:

Hi,
My apologies. Thank you for the feedback. Hopefully this is better. :grinning:
Below is a public link to better reference images. As well as, the code between the back ticks.
Link to reference images and code

function zoneparse(range) {
  delimiter = "\n"
  targetColumn = 10

  var output2 = [];
  for(var i=0, iLen=range.length; i<iLen; i++) {
    var s = range[i][targetColumn].split(delimiter);    
    for(var j=0, jLen=s.length; j<jLen; j++) {
      var output1 = []; 
      for(var k=0, kLen=range[0].length; k<kLen; k++) {
        if(k == targetColumn) {
          output1.push(s[j]);
        } else {
          output1.push(range[i][k]);
        }
      }
      output2.push(output1);
    }    
  }
  return output2;
}