往数组allCourse中的对象添加一个新的数组children:
let allCourse=[
{courseId: 20, courseName: "数据结构(C语言版)"},
{courseId: 22, courseName: "体验课程(游客)"},
{courseId: 26, courseName: "C程序设计"}
]
let data: [
{classId: 32, className: "计科19(0)班"},
{classId: 63, className: "计算机科学与技术20(6)"},
{classId: 62, className: "计算机科学与技术20(5)"},
{classId: 60, className: "计算机科学与技术20(2)"},
{classId: 61, className: "计算机科学与技术20(1)"},
{classId: 64, className: "数据结构_教师测试21(0)"},
{classId: 35, className: "计科20(0)班"}
]
for(let i=0;i<allCourse.length;i++){
allCourse[i]["children"]=data;
}
console.log(allCourse);
插入前:
插入后: