0

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

5
  • what's your devidedLogs data? Commented Jun 18, 2020 at 12:46
  • Please provide input data Commented Jun 18, 2020 at 12:49
  • {failedFaults: Array(0), failedProbesLogs: Array(1), failedRollbackLogs: Array(0), rollbackedLogs: Array(0), selfHealedLogs: Array(3)} Commented Jun 18, 2020 at 12:49
  • But you don't have array property inside your devidedLogs object Commented Jun 18, 2020 at 12:52
  • Each one of the values in the devidedLogs dict is an array (0 so when I go through the values of it i can do .array to each of one them Commented Jun 18, 2020 at 12:55

2 Answers 2

3

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)
}
Sign up to request clarification or add additional context in comments.

Comments

0

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 :)

1 Comment

By fetching keys, we would again need to parse the keys and get the values in front of each key. Because as per the requirement we need the values of the logs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.