-2

im trying to add a json element to an array bul the issue is to get the element i have to use a variable in the middle of the line.

classid.push(Gjason.rgInventory.+ itemid +.classid);
instanceid.push(Gjson.rgInventory.+ itemid +.instanceid);

the '+' separates what i'm trying to add, i am aware that is not how it works. any help or links to topics explaining this would be useful.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143

1 Answers1

0
classid.push(Gjason.rgInventory[itemid].classid);
instanceid.push(Gjson.rgInventory[itemid].instanceid);

The brackets can be used instead of the dot notation when selecting properties from an object, but contrary to the dot-notation, the bracket notation supports variables.

jervi
  • 160
  • 1
  • 8