0
function pushGear(id) {
    var etroData = getResponse(`https://etro.gg/api/gearsets/${id}`);
    var bisGear = [
      [etroData.jobAbbrev],
      [Number.parseFloat(etroData.weapon).toFixed(0)],
      [Number.parseFloat(etroData.offhand).toFixed(0)],
      [Number.parseFloat(etroData.head).toFixed(0)],
      [Number.parseFloat(etroData.body).toFixed(0)],
      [Number.parseFloat(etroData.hands).toFixed(0)],
      [Number.parseFloat(etroData.legs).toFixed(0)],
      [Number.parseFloat(etroData.feet).toFixed(0)],
      [Number.parseFloat(etroData.ears).toFixed(0)],
      [Number.parseFloat(etroData.neck).toFixed(0)],
      [Number.parseFloat(etroData.wrists).toFixed(0)],
      [Number.parseFloat(etroData.fingerL).toFixed(0)],
      [Number.parseFloat(etroData.fingerR).toFixed(0)]
      ];
      Logger.log(etroData.materia);
    bisGear.forEach((gear, gearIndex) => {
      if(etroData.materia.hasOwnProperty(gear[0])) {
        for (const property in etroData.materia[gear]) {
          Logger.log(Number.parseFloat(etroData.materia[gear][property]).toFixed(0));
          bisGear[gearIndex].push('test');
          Logger.log(bisGear[gearIndex]);
        }
      };
      if(uniqueItems.indexOf(gear) == -1 && !isNaN(gear)){uniqueItems.push(gear)};
    });
    Logger.log(bisGear);
    return bisGear;
}

I seem to be able to do bisGear[gearIndex].push('test'), or the log Logger.log(Number.parseFloat(etroData.materia[gear][property]).toFixed(0)); above it but when I try to do both, it seems to give this error

10:28:36 AM Error TypeError: Cannot read property '2' of undefined
(anonymous) @ GearPlanner.gs:52
pushGear    @ GearPlanner.gs:49
(anonymous) @ GearPlanner.gs:91
getGearset  @ GearPlanner.gs:91

I should be able to do both as they don't seem to be interacting with each other. Any ideas?

This is an example response from etro.gg API. I've removed some of the unused properties as stackoverflow was complaining that the post was mostly code.

{
    ...,
    "materia": {
    "35190": {
        "1": 33933,
        "2": 33933
    },
    "35192": {
        "1": 33933,
        "2": 33934
    },
    "35193": {
        "1": 33932,
        "2": 33932
    },
    "35194": {
        "1": 33933,
        "2": 33933
    },
    "35230": {
        "1": 33932,
        "2": 33933
    },
    "35235": {
        "1": 33932,
        "2": 33934
    },
    "35247": {
        "1": 33933,
        "2": 33933
    },
    "35265": {
        "1": 33932,
        "2": 33932
    },
    "35266": {
        "1": 33933,
        "2": 33933
    },
    "35269": {
        "1": 33933,
        "2": 33933
    },
    "35300": {
        "1": 33933,
        "2": 33934
    },
    "35090R": {
        "1": 33932,
        "2": 33934,
        "3": 33921,
        "4": 33921,
        "5": 33921
    },
    "35315L": {
        "1": 33933,
        "2": 33934
    },
    "36788R": {
        "1": 33932,
        "2": 33941
    }
},
    ...,
    "weapon": 35247,
    "head": 35190,
    "body": 35266,
    "hands": 35192,
    "legs": 35193,
    "feet": 35269,
    "offHand": null,
    "ears": 35300,
    "neck": 35230,
    "wrists": 35235,
    "fingerL": 35315,
    "fingerR": 36788,
    "food": 545,
    "medicine": null
}
Wei He
  • 1
  • 1
  • 1
    Perhaps if you could share a portion of the etro.gg/api/gearset response we could assist you in debugging your script. – TheWizEd Jul 19 '22 at 18:10

1 Answers1

0

Array bigGear is an array of arrays of numbers. You should leave them as strings. You translate to a number. Now in Number.parseFloat(etroData.materia[gear][property] gear is a number 35190 or the 35190 row of an array but needs to be a string "35190".

See this article Object property name as number

TheWizEd
  • 7,517
  • 2
  • 11
  • 19