Exploring Dialogflow, I aim to retrieve the speech value for the object in the messages array that lacks a platform key:
"messages": [
{
"type": 0,
"platform": "skype",
"speech": "FOO"
},
{
"type": 0,
"platform": "line",
"speech": "FOO"
},
{
"type": 0,
"platform": "facebook",
"speech": "FOO"
},
{
"type": 0,
"platform": "telegram",
"speech": "FOO"
},
{
"type": 0,
"platform": "kik",
"speech": "FOO"
},
{
"type": 0,
"speech": "FOO"
}
]
Currently, retrieving the value as follows:
messages = messages[messages.length - 1].speech;
However, relying on the last item being platform neutral is risky.
This was attempted:
console.log(messages.filter(function(obj) {
if (!(obj.hasOwnProperty('platform'))){
return obj;
}
}));
An error occured
TypeError: messages.map is not a function
How should the map function be adjusted for this scenario?