here is such a mistake Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'forEach') (anonymous function) http://localhost:3000/portfolio/arbitunity/static/js/main.chunk.js:3059:30 3056 | 3057 | dataset.forEach(exchange => { 3058 | // then iterate over every coin
3059 | exchange.pairs.formatted.forEach(coin => { | ^ 3060 | // map over already processed coins (uniqueCoinsAndPrices) 3061 | // check if entry of said coin already exists 3062 | const found = uniqueCoinsAndPrices.some(item => item.name === coin.name); // if not found, push a new object (inluding coin name) to array View source getUniqueCoinsAndPrices C:/Users/Admin/Desktop/arbitunity-master/src/functions/calculations/getUniqueCoinsAndPrices.js:5 2 | const uniqueCoinsAndPrices = []; 3 | 4 | // iterate over every exchange 5 | dataset.forEach((exchange) => { | ^ 6 | // then iterate over every coin 7 | exchange.pairs.formatted.forEach((coin) => { 8 | // map over already processed coins (uniqueCoinsAndPrices)
export const getUniqueCoinsAndPrices = (dataset) => {
const uniqueCoinsAndPrices = [];
// iterate over every exchange
dataset.forEach((exchange) => {
// then iterate over every coin
exchange.pairs.formatted.forEach((coin) => {
// map over already processed coins (uniqueCoinsAndPrices)
// check if entry of said coin already exists
const found = uniqueCoinsAndPrices.some(
(item) => item.name === coin.name
);
// if not found, push a new object (inluding coin name) to array
if (!found) {
uniqueCoinsAndPrices.push({
name: coin.name,
id: coin.id,
priceList: [
{
exchange: `${exchange.name}`,
price: coin.price,
},
],
});
}
// if found -> check at which index,
// update only the price (add price @ ExchangeXYZ to list)
// (useless on the first exchange, but needed for comparing data of multiple ones)
else {
const index = uniqueCoinsAndPrices
.map((element) => element.name)
.indexOf(coin.name);
uniqueCoinsAndPrices[index].priceList.push({
exchange: `${exchange.name}`,
price: coin.price,
});
}
});
});
return uniqueCoinsAndPrices;
};
enter image description here