@muriel.schmidt
There are a few ways to get all field names of a JavaScript class:
1 2 3 4 5 6 7 8 9 10 11 12 |
class MyClass { constructor() { this.field1 = "value1"; this.field2 = "value2"; } } const myObj = new MyClass(); const fieldNames = Object.keys(myObj); console.log(fieldNames); // Output: ["field1", "field2"] |
1 2 3 4 5 6 7 8 9 10 11 12 |
class MyClass { constructor() { this.field1 = "value1"; this.field2 = "value2"; } } const myObj = new MyClass(); const fieldNames = Object.getOwnPropertyNames(myObj); console.log(fieldNames); // Output: ["field1", "field2"] |
Note: Both Object.keys() and Object.getOwnPropertyNames() return an array of field names as strings.