You can use the Array.prototype.reduce() method to separate the values into different arrays. The reduce() method takes a callback function as an argument, which is used to iterate through the array and return a single value. In this case, you can use the callback function to create a new object with the different currency values as properties.
function fillOutlayGraph(barChatData, allCurrencies) {
const dateValues = [];
const currencyValues = allCurrencies.reduce((acc, currency) => {
acc[currency.name] = [];
return acc;
}, {});
for (let i = 0; i < barChatData.length; i++) {
const item = barChatData[i];
allCurrencies.forEach(function (currency) {
if (item.currencies[currency.name] == null) {
currencyValues[currency.name].push("0");
} else {
currencyValues[currency.name].push(item.currencies[currency.name]);
}
})
dateValues.push(item.date);
}
allCurrencyValues = currencyValues;
created_date = dateValues;
}
The currencyValues object will contain the different currency values as properties, which can then be accessed as needed.