Reputation: 87
trying to go through a dictionary and get values and get each of the array values in it to manipluate them but get this error, at first I thought it might be because I forgot the semi-colon at the line that defines the dict but the error stays.
getPieChartSeries(logsList){
let devidedLogs = this.divideLogsByExitCode(logsList);
console.log(devidedLogs);
let pieChartSeries = [];
Object.values(devidedLogs).array.forEach(element => {
pieChartSeries.push(this.getPrecentageOfLogType(element,logsList))
});
console.log(pieChartSeries)
}
getPrecentageOfLogType(logsList,logsOfTypeList){
let numOflogs = logsList.length
let numOflogsOfType = logsOfTypeList.length
let precentageOfLogType = Math.round((numOflogsOfType / numOflogs ) * 100)
return precentageOfLogType
}
getCurrentTime(){
var d = new Date();
return d.toLocaleString()
}
devidedLogs is
{failedFaults: Array(0), failedProbesLogs: Array(1), failedRollbackLogs: Array(0), rollbackedLogs: Array(0), selfHealedLogs: Array(3)}failedFaults: []failedProbesLogs: [{…}]failedRollbackLogs: []rollbackedLogs: []selfHealedLogs: (3) [{…}, {…}, {…}]__proto__: Object
Upvotes: 0
Views: 214
Reputation: 1
Object.values(devidedLogs)
will return an Array of all Object values, equivalently, you can use Object.keys(devidedLogs)
to obtain the keys or Object.entries(devidedLogs)
for an Array of key-value tuples.
Check also the docs of the Object class :)
Upvotes: 0
Reputation: 1486
I think you are iterating on the wrong variable.
Already .values() return the array, you don't have to add .array again after that.
So your code should be updated to the below lines:
getPieChartSeries(logsList){
let devidedLogs = this.divideLogsByExitCode(logsList);
console.log(devidedLogs);
let pieChartSeries = [];
Object.values(devidedLogs).forEach(element => {
pieChartSeries.push(this.getPrecentageOfLogType(element,logsList))
});
console.log(pieChartSeries)
}
Upvotes: 3