I successfully transferred JSON data from the server-side to the client-side. However, I encountered an issue with a function that is supposed to return the latest rate
and currency_id
. This function works for some products but not for others.
When using the function for product_id
1
and 2
, it functions properly and returns the correct array. However, when trying product_id
3
and 4
, it only returns an empty array. The function in question is provided below:
JS function:
COMNAME.prepEdit = function (product_id) {
const currencyIds = [];
const result = [];
const sortData = COMNAME.newCurrency
.filter((item) => item.product_id === product_id)
.sort((item1, item2) => item1.id - item2.id);
for (let i = sortData.length - 1; i > 0; i--) {
const item = sortData[i];
if(!currencyIds.includes(item.currency_id)) {
currencyIds.push(item.currency_id)
result.unshift(item);
}
}
return result;
}
I am seeking assistance in identifying the cause of this discrepancy. Your help is greatly appreciated. Thank you.