[Vuejs]-How to get data in array JSON many layers

0👍

Your lessonsCourse property gets overwritten in each forEach cycle.

You can use spread operator to concatenate the section lessons array to your main array:

this.eventCourse.forEach(course => {
  course.sections.forEach(section => {
    this.lessonsCourse = [...this.lessonsCourse, ...section.lessons];
  });
});

Or, if your compiler doesn’t support spread syntax using push:

this.eventCourse.forEach(course => {
  course.sections.forEach(section => {
    section.lessons.forEach(lesson => {
      this.lessonsCourse.push(lesson);
    });
  });
});

Leave a comment