@E1cid thanks for the reply.
If i use the push function i need somthing like this:
msg.startdate = new Date();
var entries = Object.entries(msg.payload);
var entrieslength = entries.length;
var MainArray = [[]];
var PushArray = [];
var i;
var i2 = 0;
var n;
var FirstScan = 0;
var Topic;
for (i=0; i!==10; i++) {
Topic = entries[i][0].split("$");
if (FirstScan === 0) {
PrevTopic = Topic[0];
firstscan = 1;
MainArray[i2][].push(['Parameters','Actual Value','Prev Value','Date Changed','Comment']);
}
if (Topic[0] !== PrevTopic) {
i2++;
MainArray[i2][].push(['Parameters','Actual Value','Prev Value','Date Changed','Comment']);
PrevTopic = Topic[0];
}
MainArray[i2][].push([Topic[0],entries[i][1],Math.random(),new Date(),Topic[1]]);
}
msg.payload = MainArray;
return msg;
But the problem is Javascript doen't know that syntax that
MainArray[i2][].push()
I tried it with this approach and it works.
var MainArray = [[]];
var PushArray0 = [];
var PushArray1 = [];
MainArray[0] = PushArray0;
MainArray[1] = PushArray1;
MainArray[i] = PushArrayi;
As you can see for every MainArray[i][j] i value i need a new PushArray because i tried it with 1 PushArray and every line in the MainArray gets the same value of the latest PushArray.
What i find strange! Because i thought that if you store a value in MainArray[0] it's saved in that Array on that spot and if i write the second place or any other the value stored in spot 0 doesn't look back at the var that stored it (if that make sense). I don't have the original code anymore i will try to recreate it and send it over.
That's why my original question (which was a little chaotic) was if i could make of the PushArray(i) variable so the code could be alot smaller like example:
var MainArray = [[]];
var PushArray($j) = [];
var i;
var j;
MainArray[i].push(PushArray($j));
or
var MainArray = [[]];
var PushArray(1) = [];
var PushArray(2) = [];
var PushArray(n) = [];
var i;
var j;
if (j<=n) MainArray[i].push(PushArray($j));