0

I have this data:

{ moteid: 'AA:11',
  temperature: '32',
  humidity: '17.0',
  readingDate: 2017-03-12T14:12:00.000Z,
  _id: 5940221b2c4e2c63974609af }

Which I get by doing the following:

result.forEach(function(entries) {
  console.log(entries);
})

How can I get the field names (i.e.: moteid, temperature, humidity, readingDate) in runtime to an array?

I want the field names so in the next steps I can use them as variables. I don't want the values, just the keys.

And I want the unique values, so if I have 100 records, I just want the key to be shwon once.

joarafa
  • 3
  • 3

1 Answers1

0

Use Object.keys()

var result =  { 
 moteid: 'AA:11',
 temperature: '32',
 humidity: '17.0',
 readingDate: new Date(2017-03-12T14:12:00.000Z),
 _id: "5940221b2c4e2c63974609af"
 }

var attributes = Object.keys(result);

console.log(attributes)
// [ 'moteid', 'temperature', 'humidity', 'readingDate', '_id' ]
Sam Quinn
  • 3,310
  • 1
  • 16
  • 11