Home > Software engineering >  How can I make script run function on every value on the array? Apps Script
How can I make script run function on every value on the array? Apps Script

Time:08-16

My current code has an array dropsB that contains 1300 values, my function currently finds only the first value in this array dropsB[0] in itemDB and then returns the information it finds with that ID in a new filtered chart.

function GetDrops() {
    // Sheets Variables
    var mobItemDB = SpreadsheetApp.getActiveSpreadsheet()
    var mobDB = mobItemDB.getSheetByName('mobDB')
    var itemDB = mobItemDB.getSheetByName('itemDB')
    var itemDBLastRow = itemDB.getLastRow()
    var itemDBLastColumn = itemDB.getLastColumn()
    var itemArray = itemDB.getRange(8,1,itemDBLastRow-7,itemDBLastColumn).getValues()
    var healing = mobItemDB.getSheetByName('0 Healing')
    var usable = mobItemDB.getSheetByName('2-11-18 Usable')
    var loot = mobItemDB.getSheetByName('3 Loot')
    var armor = mobItemDB.getSheetByName('4a Armor')
    var shield = mobItemDB.getSheetByName('4b Shield')
    var headgear = mobItemDB.getSheetByName('4c Headgear')
    var garment = mobItemDB.getSheetByName('4d Garment')
    var footgear = mobItemDB.getSheetByName('4e Footgear')
    var accessory = mobItemDB.getSheetByName('4f Accessory')
    var weapons = mobItemDB.getSheetByName('5 Weapons')
    var cards = mobItemDB.getSheetByName('6 Cards')
    var eggs = mobItemDB.getSheetByName('7 Eggs')
    var petArmor = mobItemDB.getSheetByName('8 Pet Armor')
    var ammo = mobItemDB.getSheetByName('10 Ammo')
    
    // ######################################## All Drop Cells ########################################
    var dropsA = mobDB.getRange(3, 37, 101, 26).getValues();
    var dropsB = [dropsA[0][0], dropsA[0][2], dropsA[0][4], dropsA[0][6], dropsA[0][8], dropsA[0][10], dropsA[0][12], dropsA[0][14], dropsA[0][16], dropsA[0][18], dropsA[0][20], dropsA[0][22], dropsA[0][24],
                dropsA[1][0], dropsA[1][2], dropsA[1][4], dropsA[1][6], dropsA[1][8], dropsA[1][10], dropsA[1][12], dropsA[1][14], dropsA[1][16], dropsA[1][18], dropsA[1][20], dropsA[1][22], dropsA[1][24],
                dropsA[2][0], dropsA[2][2], dropsA[2][4], dropsA[2][6], dropsA[2][8], dropsA[2][10], dropsA[2][12], dropsA[2][14], dropsA[2][16], dropsA[2][18], dropsA[2][20], dropsA[2][22], dropsA[2][24],
                dropsA[3][0], dropsA[3][2], dropsA[3][4], dropsA[3][6], dropsA[3][8], dropsA[3][10], dropsA[3][12], dropsA[3][14], dropsA[3][16], dropsA[3][18], dropsA[3][20], dropsA[3][22], dropsA[3][24],
                dropsA[4][0], dropsA[4][2], dropsA[4][4], dropsA[4][6], dropsA[4][8], dropsA[4][10], dropsA[4][12], dropsA[4][14], dropsA[4][16], dropsA[4][18], dropsA[4][20], dropsA[4][22], dropsA[4][24],
                dropsA[5][0], dropsA[5][2], dropsA[5][4], dropsA[5][6], dropsA[5][8], dropsA[5][10], dropsA[5][12], dropsA[5][14], dropsA[5][16], dropsA[5][18], dropsA[5][20], dropsA[5][22], dropsA[5][24],
                dropsA[6][0], dropsA[6][2], dropsA[6][4], dropsA[6][6], dropsA[6][8], dropsA[6][10], dropsA[6][12], dropsA[6][14], dropsA[6][16], dropsA[6][18], dropsA[6][20], dropsA[6][22], dropsA[6][24],
                dropsA[7][0], dropsA[7][2], dropsA[7][4], dropsA[7][6], dropsA[7][8], dropsA[7][10], dropsA[7][12], dropsA[7][14], dropsA[7][16], dropsA[7][18], dropsA[7][20], dropsA[7][22], dropsA[7][24],
                dropsA[8][0], dropsA[8][2], dropsA[8][4], dropsA[8][6], dropsA[8][8], dropsA[8][10], dropsA[8][12], dropsA[8][14], dropsA[8][16], dropsA[8][18], dropsA[8][20], dropsA[8][22], dropsA[8][24],
                dropsA[9][0], dropsA[9][2], dropsA[9][4], dropsA[9][6], dropsA[9][8], dropsA[9][10], dropsA[9][12], dropsA[9][14], dropsA[9][16], dropsA[9][18], dropsA[9][20], dropsA[9][22], dropsA[9][24],
                dropsA[10][0], dropsA[10][2], dropsA[10][4], dropsA[10][6], dropsA[10][8], dropsA[10][10], dropsA[10][12], dropsA[10][14], dropsA[10][16], dropsA[10][18], dropsA[10][20], dropsA[10][22], dropsA[10][24],
                dropsA[11][0], dropsA[11][2], dropsA[11][4], dropsA[11][6], dropsA[11][8], dropsA[11][10], dropsA[11][12], dropsA[11][14], dropsA[11][16], dropsA[11][18], dropsA[11][20], dropsA[11][22], dropsA[11][24],
                dropsA[12][0], dropsA[12][2], dropsA[12][4], dropsA[12][6], dropsA[12][8], dropsA[12][10], dropsA[12][12], dropsA[12][14], dropsA[12][16], dropsA[12][18], dropsA[12][20], dropsA[12][22], dropsA[12][24],
                dropsA[13][0], dropsA[13][2], dropsA[13][4], dropsA[13][6], dropsA[13][8], dropsA[13][10], dropsA[13][12], dropsA[13][14], dropsA[13][16], dropsA[13][18], dropsA[13][20], dropsA[13][22], dropsA[13][24],
                dropsA[14][0], dropsA[14][2], dropsA[14][4], dropsA[14][6], dropsA[14][8], dropsA[14][10], dropsA[14][12], dropsA[14][14], dropsA[14][16], dropsA[14][18], dropsA[14][20], dropsA[14][22], dropsA[14][24],
                dropsA[15][0], dropsA[15][2], dropsA[15][4], dropsA[15][6], dropsA[15][8], dropsA[15][10], dropsA[15][12], dropsA[15][14], dropsA[15][16], dropsA[15][18], dropsA[15][20], dropsA[15][22], dropsA[15][24],
                dropsA[16][0], dropsA[16][2], dropsA[16][4], dropsA[16][6], dropsA[16][8], dropsA[16][10], dropsA[16][12], dropsA[16][14], dropsA[16][16], dropsA[16][18], dropsA[16][20], dropsA[16][22], dropsA[16][24],
                dropsA[17][0], dropsA[17][2], dropsA[17][4], dropsA[17][6], dropsA[17][8], dropsA[17][10], dropsA[17][12], dropsA[17][14], dropsA[17][16], dropsA[17][18], dropsA[17][20], dropsA[17][22], dropsA[17][24],
                dropsA[18][0], dropsA[18][2], dropsA[18][4], dropsA[18][6], dropsA[18][8], dropsA[18][10], dropsA[18][12], dropsA[18][14], dropsA[18][16], dropsA[18][18], dropsA[18][20], dropsA[18][22], dropsA[18][24],
                dropsA[19][0], dropsA[19][2], dropsA[19][4], dropsA[19][6], dropsA[19][8], dropsA[19][10], dropsA[19][12], dropsA[19][14], dropsA[19][16], dropsA[19][18], dropsA[19][20], dropsA[19][22], dropsA[19][24],
                dropsA[20][0], dropsA[20][2], dropsA[20][4], dropsA[20][6], dropsA[20][8], dropsA[20][10], dropsA[20][12], dropsA[20][14], dropsA[20][16], dropsA[20][18], dropsA[20][20], dropsA[20][22], dropsA[20][24],
                dropsA[21][0], dropsA[21][2], dropsA[21][4], dropsA[21][6], dropsA[21][8], dropsA[21][10], dropsA[21][12], dropsA[21][14], dropsA[21][16], dropsA[21][18], dropsA[21][20], dropsA[21][22], dropsA[21][24],
                dropsA[22][0], dropsA[22][2], dropsA[22][4], dropsA[22][6], dropsA[22][8], dropsA[22][10], dropsA[22][12], dropsA[22][14], dropsA[22][16], dropsA[22][18], dropsA[22][20], dropsA[22][22], dropsA[22][24],
                dropsA[23][0], dropsA[23][2], dropsA[23][4], dropsA[23][6], dropsA[23][8], dropsA[23][10], dropsA[23][12], dropsA[23][14], dropsA[23][16], dropsA[23][18], dropsA[23][20], dropsA[23][22], dropsA[23][24],
                dropsA[24][0], dropsA[24][2], dropsA[24][4], dropsA[24][6], dropsA[24][8], dropsA[24][10], dropsA[24][12], dropsA[24][14], dropsA[24][16], dropsA[24][18], dropsA[24][20], dropsA[24][22], dropsA[24][24],
                dropsA[25][0], dropsA[25][2], dropsA[25][4], dropsA[25][6], dropsA[25][8], dropsA[25][10], dropsA[25][12], dropsA[25][14], dropsA[25][16], dropsA[25][18], dropsA[25][20], dropsA[25][22], dropsA[25][24],
                dropsA[26][0], dropsA[26][2], dropsA[26][4], dropsA[26][6], dropsA[26][8], dropsA[26][10], dropsA[26][12], dropsA[26][14], dropsA[26][16], dropsA[26][18], dropsA[26][20], dropsA[26][22], dropsA[26][24],
                dropsA[27][0], dropsA[27][2], dropsA[27][4], dropsA[27][6], dropsA[27][8], dropsA[27][10], dropsA[27][12], dropsA[27][14], dropsA[27][16], dropsA[27][18], dropsA[27][20], dropsA[27][22], dropsA[27][24],
                dropsA[28][0], dropsA[28][2], dropsA[28][4], dropsA[28][6], dropsA[28][8], dropsA[28][10], dropsA[28][12], dropsA[28][14], dropsA[28][16], dropsA[28][18], dropsA[28][20], dropsA[28][22], dropsA[28][24],
                dropsA[29][0], dropsA[29][2], dropsA[29][4], dropsA[29][6], dropsA[29][8], dropsA[29][10], dropsA[29][12], dropsA[29][14], dropsA[29][16], dropsA[29][18], dropsA[29][20], dropsA[29][22], dropsA[29][24],
                dropsA[30][0], dropsA[30][2], dropsA[30][4], dropsA[30][6], dropsA[30][8], dropsA[30][10], dropsA[30][12], dropsA[30][14], dropsA[30][16], dropsA[30][18], dropsA[30][20], dropsA[30][22], dropsA[30][24],
                dropsA[31][0], dropsA[31][2], dropsA[31][4], dropsA[31][6], dropsA[31][8], dropsA[31][10], dropsA[31][12], dropsA[31][14], dropsA[31][16], dropsA[31][18], dropsA[31][20], dropsA[31][22], dropsA[31][24],
                dropsA[32][0], dropsA[32][2], dropsA[32][4], dropsA[32][6], dropsA[32][8], dropsA[32][10], dropsA[32][12], dropsA[32][14], dropsA[32][16], dropsA[32][18], dropsA[32][20], dropsA[32][22], dropsA[32][24],
                dropsA[33][0], dropsA[33][2], dropsA[33][4], dropsA[33][6], dropsA[33][8], dropsA[33][10], dropsA[33][12], dropsA[33][14], dropsA[33][16], dropsA[33][18], dropsA[33][20], dropsA[33][22], dropsA[33][24],
                dropsA[34][0], dropsA[34][2], dropsA[34][4], dropsA[34][6], dropsA[34][8], dropsA[34][10], dropsA[34][12], dropsA[34][14], dropsA[34][16], dropsA[34][18], dropsA[34][20], dropsA[34][22], dropsA[34][24],
                dropsA[35][0], dropsA[35][2], dropsA[35][4], dropsA[35][6], dropsA[35][8], dropsA[35][10], dropsA[35][12], dropsA[35][14], dropsA[35][16], dropsA[35][18], dropsA[35][20], dropsA[35][22], dropsA[35][24],
                dropsA[36][0], dropsA[36][2], dropsA[36][4], dropsA[36][6], dropsA[36][8], dropsA[36][10], dropsA[36][12], dropsA[36][14], dropsA[36][16], dropsA[36][18], dropsA[36][20], dropsA[36][22], dropsA[36][24],
                dropsA[37][0], dropsA[37][2], dropsA[37][4], dropsA[37][6], dropsA[37][8], dropsA[37][10], dropsA[37][12], dropsA[37][14], dropsA[37][16], dropsA[37][18], dropsA[37][20], dropsA[37][22], dropsA[37][24],
                dropsA[38][0], dropsA[38][2], dropsA[38][4], dropsA[38][6], dropsA[38][8], dropsA[38][10], dropsA[38][12], dropsA[38][14], dropsA[38][16], dropsA[38][18], dropsA[38][20], dropsA[38][22], dropsA[38][24],
                dropsA[39][0], dropsA[39][2], dropsA[39][4], dropsA[39][6], dropsA[39][8], dropsA[39][10], dropsA[39][12], dropsA[39][14], dropsA[39][16], dropsA[39][18], dropsA[39][20], dropsA[39][22], dropsA[39][24],
                dropsA[40][0], dropsA[40][2], dropsA[40][4], dropsA[40][6], dropsA[40][8], dropsA[40][10], dropsA[40][12], dropsA[40][14], dropsA[40][16], dropsA[40][18], dropsA[40][20], dropsA[40][22], dropsA[40][24],
                dropsA[41][0], dropsA[41][2], dropsA[41][4], dropsA[41][6], dropsA[41][8], dropsA[41][10], dropsA[41][12], dropsA[41][14], dropsA[41][16], dropsA[41][18], dropsA[41][20], dropsA[41][22], dropsA[41][24],
                dropsA[42][0], dropsA[42][2], dropsA[42][4], dropsA[42][6], dropsA[42][8], dropsA[42][10], dropsA[42][12], dropsA[42][14], dropsA[42][16], dropsA[42][18], dropsA[42][20], dropsA[42][22], dropsA[42][24],
                dropsA[43][0], dropsA[43][2], dropsA[43][4], dropsA[43][6], dropsA[43][8], dropsA[43][10], dropsA[43][12], dropsA[43][14], dropsA[43][16], dropsA[43][18], dropsA[43][20], dropsA[43][22], dropsA[43][24],
                dropsA[44][0], dropsA[44][2], dropsA[44][4], dropsA[44][6], dropsA[44][8], dropsA[44][10], dropsA[44][12], dropsA[44][14], dropsA[44][16], dropsA[44][18], dropsA[44][20], dropsA[44][22], dropsA[44][24],
                dropsA[45][0], dropsA[45][2], dropsA[45][4], dropsA[45][6], dropsA[45][8], dropsA[45][10], dropsA[45][12], dropsA[45][14], dropsA[45][16], dropsA[45][18], dropsA[45][20], dropsA[45][22], dropsA[45][24],
                dropsA[46][0], dropsA[46][2], dropsA[46][4], dropsA[46][6], dropsA[46][8], dropsA[46][10], dropsA[46][12], dropsA[46][14], dropsA[46][16], dropsA[46][18], dropsA[46][20], dropsA[46][22], dropsA[46][24],
                dropsA[47][0], dropsA[47][2], dropsA[47][4], dropsA[47][6], dropsA[47][8], dropsA[47][10], dropsA[47][12], dropsA[47][14], dropsA[47][16], dropsA[47][18], dropsA[47][20], dropsA[47][22], dropsA[47][24],
                dropsA[48][0], dropsA[48][2], dropsA[48][4], dropsA[48][6], dropsA[48][8], dropsA[48][10], dropsA[48][12], dropsA[48][14], dropsA[48][16], dropsA[48][18], dropsA[48][20], dropsA[48][22], dropsA[48][24],
                dropsA[49][0], dropsA[49][2], dropsA[49][4], dropsA[49][6], dropsA[49][8], dropsA[49][10], dropsA[49][12], dropsA[49][14], dropsA[49][16], dropsA[49][18], dropsA[49][20], dropsA[49][22], dropsA[49][24],
                dropsA[50][0], dropsA[50][2], dropsA[50][4], dropsA[50][6], dropsA[50][8], dropsA[50][10], dropsA[50][12], dropsA[50][14], dropsA[50][16], dropsA[50][18], dropsA[50][20], dropsA[50][22], dropsA[50][24],
                dropsA[51][0], dropsA[51][2], dropsA[51][4], dropsA[51][6], dropsA[51][8], dropsA[51][10], dropsA[51][12], dropsA[51][14], dropsA[51][16], dropsA[51][18], dropsA[51][20], dropsA[51][22], dropsA[51][24],
                dropsA[52][0], dropsA[52][2], dropsA[52][4], dropsA[52][6], dropsA[52][8], dropsA[52][10], dropsA[52][12], dropsA[52][14], dropsA[52][16], dropsA[52][18], dropsA[52][20], dropsA[52][22], dropsA[52][24],
                dropsA[53][0], dropsA[53][2], dropsA[53][4], dropsA[53][6], dropsA[53][8], dropsA[53][10], dropsA[53][12], dropsA[53][14], dropsA[53][16], dropsA[53][18], dropsA[53][20], dropsA[53][22], dropsA[53][24],
                dropsA[54][0], dropsA[54][2], dropsA[54][4], dropsA[54][6], dropsA[54][8], dropsA[54][10], dropsA[54][12], dropsA[54][14], dropsA[54][16], dropsA[54][18], dropsA[54][20], dropsA[54][22], dropsA[54][24],
                dropsA[55][0], dropsA[55][2], dropsA[55][4], dropsA[55][6], dropsA[55][8], dropsA[55][10], dropsA[55][12], dropsA[55][14], dropsA[55][16], dropsA[55][18], dropsA[55][20], dropsA[55][22], dropsA[55][24],
                dropsA[56][0], dropsA[56][2], dropsA[56][4], dropsA[56][6], dropsA[56][8], dropsA[56][10], dropsA[56][12], dropsA[56][14], dropsA[56][16], dropsA[56][18], dropsA[56][20], dropsA[56][22], dropsA[56][24],
                dropsA[57][0], dropsA[57][2], dropsA[57][4], dropsA[57][6], dropsA[57][8], dropsA[57][10], dropsA[57][12], dropsA[57][14], dropsA[57][16], dropsA[57][18], dropsA[57][20], dropsA[57][22], dropsA[57][24],
                dropsA[58][0], dropsA[58][2], dropsA[58][4], dropsA[58][6], dropsA[58][8], dropsA[58][10], dropsA[58][12], dropsA[58][14], dropsA[58][16], dropsA[58][18], dropsA[58][20], dropsA[58][22], dropsA[58][24],
                dropsA[59][0], dropsA[59][2], dropsA[59][4], dropsA[59][6], dropsA[59][8], dropsA[59][10], dropsA[59][12], dropsA[59][14], dropsA[59][16], dropsA[59][18], dropsA[59][20], dropsA[59][22], dropsA[59][24],
                dropsA[60][0], dropsA[60][2], dropsA[60][4], dropsA[60][6], dropsA[60][8], dropsA[60][10], dropsA[60][12], dropsA[60][14], dropsA[60][16], dropsA[60][18], dropsA[60][20], dropsA[60][22], dropsA[60][24],
                dropsA[61][0], dropsA[61][2], dropsA[61][4], dropsA[61][6], dropsA[61][8], dropsA[61][10], dropsA[61][12], dropsA[61][14], dropsA[61][16], dropsA[61][18], dropsA[61][20], dropsA[61][22], dropsA[61][24],
                dropsA[62][0], dropsA[62][2], dropsA[62][4], dropsA[62][6], dropsA[62][8], dropsA[62][10], dropsA[62][12], dropsA[62][14], dropsA[62][16], dropsA[62][18], dropsA[62][20], dropsA[62][22], dropsA[62][24],
                dropsA[63][0], dropsA[63][2], dropsA[63][4], dropsA[63][6], dropsA[63][8], dropsA[63][10], dropsA[63][12], dropsA[63][14], dropsA[63][16], dropsA[63][18], dropsA[63][20], dropsA[63][22], dropsA[63][24],
                dropsA[64][0], dropsA[64][2], dropsA[64][4], dropsA[64][6], dropsA[64][8], dropsA[64][10], dropsA[64][12], dropsA[64][14], dropsA[64][16], dropsA[64][18], dropsA[64][20], dropsA[64][22], dropsA[64][24],
                dropsA[65][0], dropsA[65][2], dropsA[65][4], dropsA[65][6], dropsA[65][8], dropsA[65][10], dropsA[65][12], dropsA[65][14], dropsA[65][16], dropsA[65][18], dropsA[65][20], dropsA[65][22], dropsA[65][24],
                dropsA[66][0], dropsA[66][2], dropsA[66][4], dropsA[66][6], dropsA[66][8], dropsA[66][10], dropsA[66][12], dropsA[66][14], dropsA[66][16], dropsA[66][18], dropsA[66][20], dropsA[66][22], dropsA[66][24],
                dropsA[67][0], dropsA[67][2], dropsA[67][4], dropsA[67][6], dropsA[67][8], dropsA[67][10], dropsA[67][12], dropsA[67][14], dropsA[67][16], dropsA[67][18], dropsA[67][20], dropsA[67][22], dropsA[67][24],
                dropsA[68][0], dropsA[68][2], dropsA[68][4], dropsA[68][6], dropsA[68][8], dropsA[68][10], dropsA[68][12], dropsA[68][14], dropsA[68][16], dropsA[68][18], dropsA[68][20], dropsA[68][22], dropsA[68][24],
                dropsA[69][0], dropsA[69][2], dropsA[69][4], dropsA[69][6], dropsA[69][8], dropsA[69][10], dropsA[69][12], dropsA[69][14], dropsA[69][16], dropsA[69][18], dropsA[69][20], dropsA[69][22], dropsA[69][24],
                dropsA[70][0], dropsA[70][2], dropsA[70][4], dropsA[70][6], dropsA[70][8], dropsA[70][10], dropsA[70][12], dropsA[70][14], dropsA[70][16], dropsA[70][18], dropsA[70][20], dropsA[70][22], dropsA[70][24],
                dropsA[71][0], dropsA[71][2], dropsA[71][4], dropsA[71][6], dropsA[71][8], dropsA[71][10], dropsA[71][12], dropsA[71][14], dropsA[71][16], dropsA[71][18], dropsA[71][20], dropsA[71][22], dropsA[71][24],
                dropsA[72][0], dropsA[72][2], dropsA[72][4], dropsA[72][6], dropsA[72][8], dropsA[72][10], dropsA[72][12], dropsA[72][14], dropsA[72][16], dropsA[72][18], dropsA[72][20], dropsA[72][22], dropsA[72][24],
                dropsA[73][0], dropsA[73][2], dropsA[73][4], dropsA[73][6], dropsA[73][8], dropsA[73][10], dropsA[73][12], dropsA[73][14], dropsA[73][16], dropsA[73][18], dropsA[73][20], dropsA[73][22], dropsA[73][24],
                dropsA[74][0], dropsA[74][2], dropsA[74][4], dropsA[74][6], dropsA[74][8], dropsA[74][10], dropsA[74][12], dropsA[74][14], dropsA[74][16], dropsA[74][18], dropsA[74][20], dropsA[74][22], dropsA[74][24],
                dropsA[75][0], dropsA[75][2], dropsA[75][4], dropsA[75][6], dropsA[75][8], dropsA[75][10], dropsA[75][12], dropsA[75][14], dropsA[75][16], dropsA[75][18], dropsA[75][20], dropsA[75][22], dropsA[75][24],
                dropsA[76][0], dropsA[76][2], dropsA[76][4], dropsA[76][6], dropsA[76][8], dropsA[76][10], dropsA[76][12], dropsA[76][14], dropsA[76][16], dropsA[76][18], dropsA[76][20], dropsA[76][22], dropsA[76][24],
                dropsA[77][0], dropsA[77][2], dropsA[77][4], dropsA[77][6], dropsA[77][8], dropsA[77][10], dropsA[77][12], dropsA[77][14], dropsA[77][16], dropsA[77][18], dropsA[77][20], dropsA[77][22], dropsA[77][24],
                dropsA[78][0], dropsA[78][2], dropsA[78][4], dropsA[78][6], dropsA[78][8], dropsA[78][10], dropsA[78][12], dropsA[78][14], dropsA[78][16], dropsA[78][18], dropsA[78][20], dropsA[78][22], dropsA[78][24],
                dropsA[79][0], dropsA[79][2], dropsA[79][4], dropsA[79][6], dropsA[79][8], dropsA[79][10], dropsA[79][12], dropsA[79][14], dropsA[79][16], dropsA[79][18], dropsA[79][20], dropsA[79][22], dropsA[79][24],
                dropsA[80][0], dropsA[80][2], dropsA[80][4], dropsA[80][6], dropsA[80][8], dropsA[80][10], dropsA[80][12], dropsA[80][14], dropsA[80][16], dropsA[80][18], dropsA[80][20], dropsA[80][22], dropsA[80][24],
                dropsA[81][0], dropsA[81][2], dropsA[81][4], dropsA[81][6], dropsA[81][8], dropsA[81][10], dropsA[81][12], dropsA[81][14], dropsA[81][16], dropsA[81][18], dropsA[81][20], dropsA[81][22], dropsA[81][24],
                dropsA[82][0], dropsA[82][2], dropsA[82][4], dropsA[82][6], dropsA[82][8], dropsA[82][10], dropsA[82][12], dropsA[82][14], dropsA[82][16], dropsA[82][18], dropsA[82][20], dropsA[82][22], dropsA[82][24],
                dropsA[83][0], dropsA[83][2], dropsA[83][4], dropsA[83][6], dropsA[83][8], dropsA[83][10], dropsA[83][12], dropsA[83][14], dropsA[83][16], dropsA[83][18], dropsA[83][20], dropsA[83][22], dropsA[83][24],
                dropsA[84][0], dropsA[84][2], dropsA[84][4], dropsA[84][6], dropsA[84][8], dropsA[84][10], dropsA[84][12], dropsA[84][14], dropsA[84][16], dropsA[84][18], dropsA[84][20], dropsA[84][22], dropsA[84][24],
                dropsA[85][0], dropsA[85][2], dropsA[85][4], dropsA[85][6], dropsA[85][8], dropsA[85][10], dropsA[85][12], dropsA[85][14], dropsA[85][16], dropsA[85][18], dropsA[85][20], dropsA[85][22], dropsA[85][24],
                dropsA[86][0], dropsA[86][2], dropsA[86][4], dropsA[86][6], dropsA[86][8], dropsA[86][10], dropsA[86][12], dropsA[86][14], dropsA[86][16], dropsA[86][18], dropsA[86][20], dropsA[86][22], dropsA[86][24],
                dropsA[87][0], dropsA[87][2], dropsA[87][4], dropsA[87][6], dropsA[87][8], dropsA[87][10], dropsA[87][12], dropsA[87][14], dropsA[87][16], dropsA[87][18], dropsA[87][20], dropsA[87][22], dropsA[87][24],
                dropsA[88][0], dropsA[88][2], dropsA[88][4], dropsA[88][6], dropsA[88][8], dropsA[88][10], dropsA[88][12], dropsA[88][14], dropsA[88][16], dropsA[88][18], dropsA[88][20], dropsA[88][22], dropsA[88][24],
                dropsA[89][0], dropsA[89][2], dropsA[89][4], dropsA[89][6], dropsA[89][8], dropsA[89][10], dropsA[89][12], dropsA[89][14], dropsA[89][16], dropsA[89][18], dropsA[89][20], dropsA[89][22], dropsA[89][24],
                dropsA[90][0], dropsA[90][2], dropsA[90][4], dropsA[90][6], dropsA[90][8], dropsA[90][10], dropsA[90][12], dropsA[90][14], dropsA[90][16], dropsA[90][18], dropsA[90][20], dropsA[90][22], dropsA[90][24],
                dropsA[91][0], dropsA[91][2], dropsA[91][4], dropsA[91][6], dropsA[91][8], dropsA[91][10], dropsA[91][12], dropsA[91][14], dropsA[91][16], dropsA[91][18], dropsA[91][20], dropsA[91][22], dropsA[91][24],
                dropsA[92][0], dropsA[92][2], dropsA[92][4], dropsA[92][6], dropsA[92][8], dropsA[92][10], dropsA[92][12], dropsA[92][14], dropsA[92][16], dropsA[92][18], dropsA[92][20], dropsA[92][22], dropsA[92][24],
                dropsA[93][0], dropsA[93][2], dropsA[93][4], dropsA[93][6], dropsA[93][8], dropsA[93][10], dropsA[93][12], dropsA[93][14], dropsA[93][16], dropsA[93][18], dropsA[93][20], dropsA[93][22], dropsA[93][24],
                dropsA[94][0], dropsA[94][2], dropsA[94][4], dropsA[94][6], dropsA[94][8], dropsA[94][10], dropsA[94][12], dropsA[94][14], dropsA[94][16], dropsA[94][18], dropsA[94][20], dropsA[94][22], dropsA[94][24],
                dropsA[95][0], dropsA[95][2], dropsA[95][4], dropsA[95][6], dropsA[95][8], dropsA[95][10], dropsA[95][12], dropsA[95][14], dropsA[95][16], dropsA[95][18], dropsA[95][20], dropsA[95][22], dropsA[95][24],
                dropsA[96][0], dropsA[96][2], dropsA[96][4], dropsA[96][6], dropsA[96][8], dropsA[96][10], dropsA[96][12], dropsA[96][14], dropsA[96][16], dropsA[96][18], dropsA[96][20], dropsA[96][22], dropsA[96][24],
                dropsA[97][0], dropsA[97][2], dropsA[97][4], dropsA[97][6], dropsA[97][8], dropsA[97][10], dropsA[97][12], dropsA[97][14], dropsA[97][16], dropsA[97][18], dropsA[97][20], dropsA[97][22], dropsA[97][24],
                dropsA[98][0], dropsA[98][2], dropsA[98][4], dropsA[98][6], dropsA[98][8], dropsA[98][10], dropsA[98][12], dropsA[98][14], dropsA[98][16], dropsA[98][18], dropsA[98][20], dropsA[98][22], dropsA[98][24],
                dropsA[99][0], dropsA[99][2], dropsA[99][4], dropsA[99][6], dropsA[99][8], dropsA[99][10], dropsA[99][12], dropsA[99][14], dropsA[99][16], dropsA[99][18], dropsA[99][20], dropsA[99][22], dropsA[99][24]]
    
    
    // ######################################## Function to Filter Items ###########################################
    var matchRow = itemArray.find(r => r[0] == dropsB[0])
    var match = matchRow ? matchRow : ""
    if(match[3] == 0) {
        var healingArray = healing.getRange(1,1,healing.getLastRow(),healing.getLastColumn()).getValues()
        var matchID = healingArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            healing.getRange(healing.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 2 || match[3] == 11 || match[3] == 18) {
        var usableArray = usable.getRange(1,1,usable.getLastRow(),usable.getLastColumn()).getValues()
        var matchID = usableArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            usable.getRange(usable.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 3) {
        var lootArray = loot.getRange(1,1,loot.getLastRow(),loot.getLastColumn()).getValues()
        var matchID = lootArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            loot.getRange(loot.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 4 && match[14] == 16) {
        var armorArray = armor.getRange(1,1,armor.getLastRow(),armor.getLastColumn()).getValues()
        var matchID = armorArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            armor.getRange(armor.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 4 && match[14] == 32) {
        var shieldArray = shield.getRange(1,1,shield.getLastRow(),shield.getLastColumn()).getValues()
        var matchID = shieldArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            shield.getRange(shield.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 4 && match[14] == 1) {
        var headgearArray = headgear.getRange(1,1,headgear.getLastRow(),headgear.getLastColumn()).getValues()
        var matchID = headgearArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            headgear.getRange(headgear.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 4 && match[14] == 4) {
        var garmentArray = garment.getRange(1,1,garment.getLastRow(),garment.getLastColumn()).getValues()
        var matchID = garmentArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            garment.getRange(garment.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 4 && match[14] == 64) {
        var footgearArray = footgear.getRange(1,1,footgear.getLastRow(),footgear.getLastColumn()).getValues()
        var matchID = footgearArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            footgear.getRange(footgear.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 4 && match[14] == 8 || match[3] == 4 && matchRow[14] == 128) {
        var accessoryArray = accessory.getRange(1,1,accessory.getLastRow(),accessory.getLastColumn()).getValues()
        var matchID = accessoryArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            accessory.getRange(accessory.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 5) {
        var weaponsArray = weapons.getRange(1,1,weapons.getLastRow(),weapons.getLastColumn()).getValues()
        var matchID = weaponsArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            weapons.getRange(weapons.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 6) {
        var cardsArray = cards.getRange(1,1,cards.getLastRow(),cards.getLastColumn()).getValues()
        var matchID = cardsArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            cards.getRange(cards.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 7) {
        var eggsArray = eggs.getRange(1,1,eggs.getLastRow(),eggs.getLastColumn()).getValues()
        var matchID = eggsArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            eggs.getRange(eggs.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 8) {
        var petArmorArray = petArmor.getRange(1,1,petArmor.getLastRow(),petArmor.getLastColumn()).getValues()
        var matchID = petArmorArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            petArmor.getRange(petArmor.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 10) {
        var ammoArray = ammo.getRange(1,1,ammo.getLastRow(),ammo.getLastColumn()).getValues()
        var matchID = ammoArray.find(id => id[0] == dropsB[0])
        if(matchID) {
            // Do nothing to avoid duplicates
        } else {
            ammo.getRange(ammo.getLastRow() 1,1,1,58).setValues([match])
        }
    } else if(match[3] == 12) {
        // Do nothing
    }
}

The code works like a charm, if I select the cell which belongs to dropsB[0] and change its value to any ID and then run the script, it will sort the information appropriately.

Now, I need the function to run the script and filter each one and all of the 1300 values inside of dropsB and then take each of those values throught the filter function.

How can I reproduce that function without making an unnecessary extensive code for each value on the array? dropsB[1], dropsB[2]... dropsB[1299].

CodePudding user response:

I don't really want to get into your entire code because it seems far more complex than I wish to mess with but can something like this work for you?

dropsB.forEach(e => {
  if (match[3] == 0) {
    var healingArray = healing.getRange(1, 1, healing.getLastRow(), healing.getLastColumn()).getValues()
    var matchID = healingArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      healing.getRange(healing.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 2 || match[3] == 11 || match[3] == 18) {
    var usableArray = usable.getRange(1, 1, usable.getLastRow(), usable.getLastColumn()).getValues()
    var matchID = usableArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      usable.getRange(usable.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 3) {
    var lootArray = loot.getRange(1, 1, loot.getLastRow(), loot.getLastColumn()).getValues()
    var matchID = lootArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      loot.getRange(loot.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 4 && match[14] == 16) {
    var armorArray = armor.getRange(1, 1, armor.getLastRow(), armor.getLastColumn()).getValues()
    var matchID = armorArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      armor.getRange(armor.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 4 && match[14] == 32) {
    var shieldArray = shield.getRange(1, 1, shield.getLastRow(), shield.getLastColumn()).getValues()
    var matchID = shieldArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      shield.getRange(shield.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 4 && match[14] == 1) {
    var headgearArray = headgear.getRange(1, 1, headgear.getLastRow(), headgear.getLastColumn()).getValues()
    var matchID = headgearArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      headgear.getRange(headgear.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 4 && match[14] == 4) {
    var garmentArray = garment.getRange(1, 1, garment.getLastRow(), garment.getLastColumn()).getValues()
    var matchID = garmentArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      garment.getRange(garment.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 4 && match[14] == 64) {
    var footgearArray = footgear.getRange(1, 1, footgear.getLastRow(), footgear.getLastColumn()).getValues()
    var matchID = footgearArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      footgear.getRange(footgear.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 4 && match[14] == 8 || match[3] == 4 && matchRow[14] == 128) {
    var accessoryArray = accessory.getRange(1, 1, accessory.getLastRow(), accessory.getLastColumn()).getValues()
    var matchID = accessoryArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      accessory.getRange(accessory.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 5) {
    var weaponsArray = weapons.getRange(1, 1, weapons.getLastRow(), weapons.getLastColumn()).getValues()
    var matchID = weaponsArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      weapons.getRange(weapons.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 6) {
    var cardsArray = cards.getRange(1, 1, cards.getLastRow(), cards.getLastColumn()).getValues()
    var matchID = cardsArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      cards.getRange(cards.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 7) {
    var eggsArray = eggs.getRange(1, 1, eggs.getLastRow(), eggs.getLastColumn()).getValues()
    var matchID = eggsArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      eggs.getRange(eggs.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 8) {
    var petArmorArray = petArmor.getRange(1, 1, petArmor.getLastRow(), petArmor.getLastColumn()).getValues()
    var matchID = petArmorArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      petArmor.getRange(petArmor.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 10) {
    var ammoArray = ammo.getRange(1, 1, ammo.getLastRow(), ammo.getLastColumn()).getValues()
    var matchID = ammoArray.find(id => id[0] == e)
    if (matchID) {
      // Do nothing to avoid duplicates
    } else {
      ammo.getRange(ammo.getLastRow()   1, 1, 1, 58).setValues([match])
    }
  } else if (match[3] == 12) {
    // Do nothing
  }
});

If this is not something you wish to consider let me know I'll delete it.

  • Related