I am sorting through data collected on a master sheet, and then placing it in separate sheets based on those values. The sorting and placing the data into lists isn't the issue.

I'm having trouble figuring out how to loop the placement of the data into the separate sheets. The data is already separated into lists in 2D arrays. Below is a shortened version of myt code, and at the end is the hard coded solution, but I should be able to accomplish this in a loop, right?

Ideally I should be able to run a loop through the lists and place the sorted data into the separate sheets.

```
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ml = ss.getSheetByName('Master List');
  var lists = ["list1","list2"];
  var masterlist = ml.getRange(2,2,100,100).getValues();
  var list1 = [];
  var list2 = [];
    for(i=0;i<masterlist.length;i++) {
      if(masterlist[i][2]==lists[0]){
        list1.push(masterlist[i])
      }
      if(masterlist[i][2] == lists[1]){
        list2.push(masterlist[i])
      }
    }
  ss.getSheetByName(lists[0]).getRange(2,2,list1.length,list1[0].length).clearContent();
  ss.getSheetByName(lists[0]).getRange(2,2,list1.length,list1[0].length).setValues(list1);
  ss.getSheetByName(lists[1]).getRange(2,2,list2.length,list2[0].length).clearContent();
  ss.getSheetByName(lists[1]).getRange(2,2,list2.length,list2[0].length).setValues(list2);

```

Below is a copy of what I think should work with a loop, rather than hard coding the clearContent and setValues commands, but I keep getting different errors as I fiddle with it.

```js
function Problem(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ml = ss.getSheetByName('Master List');
  var lists = ["list1","list2"];
  var masterlist = ml.getRange(2,2,100,100).getValues();
  var list1 = [];
  var list2 = [];
    for(i=0;i<masterlist.length;i++) {
      if(masterlist[i][2]==lists[0]){
        list1.push(masterlist[i])
      }
      if(masterlist[i][2] == lists[1]){
        list2.push(masterlist[i])
      }
    }
  for(j=0; j<lists.length;j++){
    ss.getSheetByName(lists[j]).getRange(2,2,lists[j].length,lists[j][0].length).clearContent();
    ss.getSheetByName(lists[j]).getRange(2,2,lists[j].length,lists[j][0].length).setValues(lists[j]);
  }
}
```

Lastly, I would love some help on how I would splice the sorting column out of my list1 and list 2 before placing them in their individual sheets.

Below is a table example of the master list.
|Col 0|Col 1|Sorting |Col 2|Col 3|
|-----|-----|--------|-----|-----|
|Data 10|Data 11|list1|Data 12|Data 13|
|Data 20|Data 21|list2|Data 22|Data 23|

I would like the data to end on each sheet as such:
List 1 Sheet.
|Col 0|Col 1|Col 2|Col 3|
|-----|-----|-----|-----|
|Data 10|Data 11|Data 12|Data 13|

List 2 Sheet.
|Col 0|Col 1|Col 2|Col 3|
|-----|-----|-----|-----|
|Data 20|Data 21|Data 22|Data 23|