1

I currently have the following in my Javascript code where Id is a field of an object:

this.recId = event.detail.row.Id;

I want to make the Id part generic something like

String a = 'Id';
this.recId = event.detail.row.a;

How do I achieve this in Javascipt

Thomas
  • 181
  • 1
  • 9

2 Answers2

2

Use [ ] instead.

const obj = {
  id: "myObject"
}

const a = "id"

console.log(obj[a]);

In your example, it would be

this.recId = event.detail.row[a];
Liftoff
  • 24,717
  • 13
  • 66
  • 119
0

You can use this.recId = event.detail.row[a] to get the desired result

Omkar
  • 157
  • 1
  • 9