In the beginning I would like to say I'm new in the world of programming.
I'm trying to implement table from excel file and do some changes on it into js environment.
Table size is 4k rows x 130 columns.
My data flow look like this:
excel.xlsx ---> node server ---> [http] angular service ----> angular component
On the server side I'm taking out the columns which I need. I successfully viewed the table into web but the problem is that somehow push() method change values of my object properties which I'm pushing into an array. For better explaining I will add some screenshots from my VSC.
This is part of the code where problem appears
And this is browser console after running the code
The value of property numOfKilometers should be 20 but in the emp obj the value is 30 idk why. The problem appears when I'm using push method, when I'm comment this line of code the problem disappears and the value of property numOfKilometers in emp obj is equal to 20 as expected.
I don't know where the problem is and why it changes exactly on 30. I'm not sure is it important but for Excel issues I'm using those two libraries: excel-date-to-js and node-xlxs.
I will be grateful for your help.
CodePudding user response:
Please post code not pictures of code. I can't really tell where the problem is but usually, we use let
to reassign variables in for-loops. Change your const
to let
.
const
is a signal that the identifier won’t be reassigned.
let
is a signal that the variable may be reassigned, such as a counter in a loop, or a value swap in an algorithm. It also signals that the variable will be used only in the block it’s defined in, which is not always the entire containing function.
let {lp, NrZam...}
let emp: makroListItem...
CodePudding user response:
Thank you for u reply.
I will remeber that for the future.
I have already found the source of the problem. In the next parts of code Im extracting unique values by customer and product name and sums the values of numOfKilometers, but unfortunately (and this is my mistake), it refers to the global instance of this object so I have changed object value in the whole project. Thats why in the previous part of code my values of the propoerty is different than expected. I forgot about that. Im going to edit this post with the code where the problem is.