I'm playing around with Dialogflow, and I would like to return the speech value for the object in the messages array that does not have a platform key assigned to it:
"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, I'm returning the value via this ugly process:
messages = messages[messages.length - 1].speech;
My concern is that I do not want to rely on the array returning the platform neutral message as the last element.
Currently, this is what I tried:
console.log(messages.map(function(obj) {
if (!(obj.hasOwnProperty('platform'))){
return obj;
}
}));
But I receive an error that states TypeError: messages.map is not a function
How should the map function be designed for such a case