I'm trying to get multiple account id's from a JSON array using the emit() method. The emit method is defined from the Alexa-SDK. The problem is that its emitting only one of the values and not all. How can I get the emit()method to return both object values in a JSON array?
Here is my code snippet:
'use strict';
const Alexa = require('alexa-sdk');
const handlers = {
'LaunchRequest': function() {
this.emit(':tell', 'sure');
this.emit('getEmployeeInfoIntent');
},
'getEmployeeInfoIntent': function() {
var empinfoData = {
"employees": [{
"account_id": 8675309
},{
"account_id": 54321
}]
};
for (var i in empinfoData) {
var employeeInfo = empinfoData[i].account_id;
this.emit(':tell', 'The accounts available are id number' + employeeInfo);
//return only 8675309 but I want 8675309 and 54321
};
}
}; ///end of handler
exports.handler = (event, context) => {
const alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};
var objtwo = { "employees": [{ "account_id": 8675309 },{ "account_id": 54321 }] } // mythis variable is defined globally var mythis = this; function getJSONArray() { //var reqresponse = this.responseText; //var objtwo = JSON.parse(reqresponse); var empinfoData = objtwo.employees; var allIds = []; for (var i of empinfoData) { var employeeInfo = i["account_id"]; allIds.push(employeeInfo); }; return allIds; }; console.log(getJSONArray());
Save the emploeeInfo's into an Array and emit the array after the loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.