Hello guys,
I want to create as output from a function an array from incoming datas like this example; example "Phone".
My code, modified from this example:
var m_out = [];
for (int i=0; i<=3; i++) {
var newmsg = {payload:msg.payload.abc[i].date, topic:"test"}
m_out.push(newmsg);
}
return [m_out];
How can I create the output as array and how can I access to the array? I dont' see in the debug an array but only the different output messages :-/
What I do wrong?
Thanks a lot!
Thank you for the fast answer @Colin
Sorry for by bad english.
Oh sorry. I try to explain it more detailed:
I get datas from a http request (format json) and can access with this command: msg.payload.abc[i].date
Now, I have to convert the datas in a oder data/time format (i have just the function) and so I want to put out the modifed datas in an array format where I can access on the single data array like msg.payload.xyz[i].
Now I try to use the javascript map function.
I'm a beginner with javascript a so I have some problems...
How the function know, which function the must run for begin and which function is a subfunction.
My code, where I hope that it works:
function outputdatetime () {
const array1= [];
for (i = 0; i <=3; i++) {
array1[i] = msg.payload.dayForecasts[i].date;
const map1 = array1.map(convertdatetime);
}
msg.payload = map1;
return msg;
}
function convertdatetime (datetime) {
var d = new Date(datetime);
var year = d.getFullYear();
var month = d.getMonth()+1;
var day = d.getDate();
if(day.toString().length==1){
day = '0' + day;
}
if(month.toString().length==1){
month = '0' + month;
}
return (day + '.' + month + '.' + year);
}
Perfect, thank you for your answer!
A general question:
In javascript how a function know, which function must run for begin and which function is a subfunction? For example i know in C/C++ it is void main().
Someone know where can I find on the web good infos for learning javascript?
Thanks!
Assuming you are talking about js in a Function node then there is no equivalent of main(). The code in the node will do nothing until it receives a message, at which time execution starts at the beginning of the Function node code. Obviously any functions defined there are skipped over to find the entry point.