I have some data pulling from a sheet. I have created an array that is sorted by the 2nd column (SKU column) below is what is returned in the spreadsheet:
In this array would like to add a blank row when the SKU changes to make it easier to read. I wrote the following code:
function update(){
var mfgSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Order Info");
var purchaseLog = SpreadsheetApp.
openById("1KkR4jE1c00WuQpPrexW8f9BIq5vxl0fWaUGxbeYERsE").
getSheetByName("Order Details");
var orderSort = purchaseLog.getRange(3, 1, purchaseLog.getLastRow(), 15).getValues().
sort(function(r1,r2){
var a = r1[1];
var b = r2[1];
if(a>b){
return 1;
}else if (a<b){
return -1;}
return 0;
}).filter(function (item){if(item[1]!=""&&item[1]!="Purchase Order Link"){return true}})
.map(function(r){return [r[0],r[1],r[2],r[5],r[6],r[11],r[13],r[12],r[8]]});
var SKUs = orderSort.map(function(r){return r[1]})
var SKUList = [];
for (var i in SKUs) {
var SKU = SKUs[i];
var duplicate = false;
for (var j in SKUList) {
if (SKU === SKUList[j]) {
duplicate = true;
}
}
if (!duplicate) {
SKUList.push(SKU);
}
}
var finalArr = []
for(var i = 0; i <= SKUList.length-1; i++){
var element = orderSort.filter(function(item){if(item[1]===SKUList[i]){return true}});
finalArr.push(element);
finalArr.push([,,,,,,,,,]);
}
Logger.log(finalArr);
}
The code almost works, but I'm getting a weird 3d Array, and I'm afraid that my logic is very wrong. Photo of the log is also included. Anyone that could help me solve this problem, it would be greatly appreciated.

