Can’t reference proprety name with ‘-‘ Nodejs

This is the output when I console.log my object using console.log(category).

{ _id: 5b723aa57bab2a0b9a0d1429,
updatedBy: 5b62743ac154c5669e9259d0,
updatedAt: 2018-08-14T09:25:20.050Z,
createdBy: 5b62743ac154c5669e9259d0,
createdAt: 2018-08-14T02:12:53.705Z,
name: 'Community Engagement',
__v: 0,
'dialogflow-agent': '8df9fab841554e8badfe2f66c74e08f3' }

But strangely when I console.log(category["dialogflow-agent"]) it gives me undefined

Does anyone know how to access the property dialogflow-agent?


Output of JSON.stringify(category) is:

{"_id":"5b6ac11920bea9751e2847e3","updatedBy":"5b62743ac154c5669e9259d0","updatedAt":"2018-08-14T09:03:54.638Z","createdBy":"5b62743ac154c5669e9259d0","createdAt":"2018-08-08T10:08:25.917Z","name":"Awards and Scholarships","__v":0,"dialogflow-agent":"26d927f3f627496fbacc08ac16af898f"}


What was missing in the question is that Category is a mongoose schema, the attributes in this schema was missing dialogflow-agent.

let categorySchema = new mongoose.Schema({
    name: String,
    'dialogflow-agent': String,    // This line was missing.

Thank you @Shilly and @T.J.Crowder for helping, and sorry for the missing info in the question. but for whoever is facing this, please check your schema.

Leave a Reply

Your email address will not be published. Required fields are marked *