-1

Can I get a variable name by code,

receivedData = { id : 1, name : 'adam', notes : ''};

how can I get the variable names in the object "id, name, notes", let's say I want to make a table from the received data and I can't hard code the columns names. is there a way to do this so I can dynamically set the columns names?

columnNames = ['id','name','notes'];
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
tamim abweini
  • 459
  • 6
  • 21

1 Answers1

1

Use Object.keys

let receivedData = {
  id: 1,
  name: 'adam',
  notes: ''
};

console.log(Object.keys(receivedData))
brk
  • 48,835
  • 10
  • 56
  • 78