0

First of all, if what I am describing in the title isn't called inheritance tell me a better word choice, I will update it. I just wasn't sure what to call it and wanted to get a solution as soon as possible.

Main file:

const items = require("../models/items")

for(var i = 0; i < 5; i++){
        if(i <= 4){
            let currentItem = profileData.items[]
            invEmbed.addFields(
                {name: `${items.currentItem.emoji}` + " " + `${items.currentItem.name} ` + " ― " + `${items.currentItem.amount}`, value: `${items.currentItem.description}`},
            ); 
        }
   }

"../models/items" Items file:

module.exports = {
    idcard: { 
        name: "ID Card",
        emoji: ":credit_card:",
        type: "tool",
        description: "Proves your identity."
    },
}

My problem is that on line 6 where I try to "items.currentItem.emoji" because I am trying to use a variable to move further in the inheritance, I am fairly new to javascript and I wanted to ask: Are you able to use variables when going through inheritance? If yes, how?

note: I am pretty sure its not called inheritance, maybe it is though, I am just using it because I don't know the proper word.

1 Answers1

0

Use bracket notation. items[currentItem].emoji or items[currentItem]["emoji"].

mykaf
  • 1,034
  • 1
  • 9
  • 12