Js uses the array reorganization method to return the course name and the number of courses

/ / returns the name of each series and the total number of courses in each series (the total number of lesson);

the environmental background of the problems and what methods you have tried

related codes

const Series = [{
  name: "Web",
  courses: [{
    name: "HTML",
    lessons: [{
      name: "HTML Lesson 1"
    },{
      name: "HTML Lesson 2"
    },{
      name: "HTML Lesson 3"
    }]
  },{
    name: "CSS",
    lessons: [{
      name: "CSS Lesson 1"
    },{
      name: "CSS Lesson 2"
    },{
      name: "CSS Lesson 3"
    },{
      name: "CSS Lesson 4"
    }]
  },{
    name: "JavaScript",
    lessons: [{
      name: "JavaScript Lesson 1"
    },{
      name: "JavaScript Lesson 2"
    }]
  }]
},{
  name: "PHP",
  courses: [{
    name: "Linux",
    lessons: [{
      name: "Linux Lesson 1"
    },{
      name: "Linux Lesson 2"
    }]
  },{
    name: "MySQL",
    lessons: [{
      name: "MySQL Lesson 1"
    },{
      name: "MySQL Lesson 2"
    },{
      name: "MySQL Lesson 3"
    },{
      name: "MySQL Lesson 4"
    }]
  },{
    name: "Nginx",
    lessons: [{
      name: "Nginx Lesson 1"
    },{
      name: "Nginx Lesson 2"
    },{
      name: "Nginx Lesson 3"
    },{
      name: "Nginx Lesson 4"
    }]
  }]
}]

function output3(Series){
 
  // ...
}
output3(Series)

sources of topics and their own ideas

aitschool
for solutions and ideas


when I finished writing, I found that I didn't seem to know much about array reorganization. You'd better put the code up, which may not quite meet the requirements of your topic

.
function output(arr) {
  return arr.map(item => {
    item.lessonCount = item.courses.reduce((total, cur) => {
      total += cur.lessons.length
      return total
    }, 0)
    delete item.courses
    return item
  })
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3166b-2bd86.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3166b-2bd86.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?