Get column (field) names from javascript Array

Viewed 28

I am looking to pull the list of column(field) names from this array. So that I end up with an array containing ['EntityId', 'RiskDescription', 'ThirdColumn', 'FourthColumn'].

var risks = [];
risks.push({
    EntityId: this.EntityID
    RiskDescription: this.RiskDescription
    ThirdColumn: this.ThirdColumn,
    FourthColumn: this.FourthColumn
});
1 Answers

You can use Object.keys to get the list of keys in that object

var risks = [];
risks.push({
  EntityId: "value",
  RiskDescription: "value",
  ThirdColumn: "value",
  FourthColumn: "value"
});

console.log(Object.keys(risks[0]))

Related