-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'];
0

1 Answer 1

1

Use Object.keys

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

console.log(Object.keys(receivedData))

Sign up to request clarification or add additional context in comments.

1 Comment

thank you I already found the answer after posting this question

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.