I have been trying to push an array of 3 values to an array to create an AOA. However my expected output is not coming out correct.
Input data looks something like the following
[
{id:xxxxx,
date:VALUE,
date:VALUE,
..months worth
},
{id:xxxx2,
date:VALUE,
date:VALUE,
..months worth
},
..loads of entries
]
please see the snip of code below.
arrayOfObjects.forEach(e =>{
let entry = [];
entry[0] = e.id;
let PC = Object.values(e)
let Dates = Object.keys(e)
PC.shift();
Dates.shift();
for(let i = 0; i <PC.length; i++){
if(PC[i] === 'No Data'){
entry[2] = 0;
entry[1] = Dates[i];
} else {
entry[2] = PC[i];
entry[1] = Dates[i];
}
finalArray.push(entry);
}
})
I am getting an array of outputs that contain the a static date
[
...
[ 'NAAAAD', '10/31/19', 0 ],
[ 'NAAAAD', '10/31/19', 0 ],
[ 'NAAAAD', '10/31/19', 0 ],
[ 'NAAAAD', '10/31/19', 0 ],
[ 'NAAAAD', '10/31/19', 0 ],
[ 'NAAAAD', '10/31/19', 0 ],
[ 'NAAAAD', '10/31/19', 0 ],
...
]
When i want to see the date increment.
[
...
[ 'NAAAAD', '10/25/19', 0 ],
[ 'NAAAAD', '10/26/19', 0 ],
[ 'NAAAAD', '10/27/19', 0 ],
[ 'NAAAAD', '10/28/19', 0 ],
[ 'NAAAAD', '10/29/19', 0 ],
[ 'NAAAAD', '10/30/19', 0 ],
[ 'NAAAAD', '10/31/19', 0 ],
...
]
I have console.log(entry)
just before it gets pushed into the array and i contains the correct information at that point? I have moved the finalArray.push(entry)
to be within the if statements directly under the line where entry is correct.
What is going on here? I am unable to find anything like this, I've considered the scope of variables, but they all seems correct.
Thanks
Ryan