0

I am trying to use type instead of 'data' in the following example, to keep it dynamic, but I have no idea how to do so, could anyone possibly advice on what to do in this case?

Thank you!

I have:

    alreadyHas: function(type) {
        return this.dropdownPlan.data.id === this.currentPlan.data.id
    },

I want:

    alreadyHas: function(type) {
        return this.dropdownPlan.type.id === this.currentPlan.type.id
    },
Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164
Deathtitan77
  • 29
  • 1
  • 8

2 Answers2

2

You could use [] Bracket notation in order to access the field dynamically :

  alreadyHas: function(type) {
        return this.dropdownPlan[type].id === this.currentPlan[type].id
    },
Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164
0

let obj = {
  row: {
    col: {
      row1: {
        title: "Done",
      },
    },
  },
};

let type = "col";
console.log(obj.row[type].row1.title);
MUHAMMAD ILYAS
  • 1,402
  • 7
  • 23