补全以下代码 <script> let stu3 = {}; stu3.name = "李四"; stu3.course = []; stu3.addCourse = function (courseId, courseName) { //为当前对象的courses属性(数组)添加元素,每个元素是一个对象(属性名为课程号,属性值为课程名) //数组.push(元素) }; addCourse(stu, "001", "高等数学"); addCourse(stu, "002", "Java"); addCourse(stu, "003", "JS")
时间: 2023-06-09 07:04:30 浏览: 124
课程信息的添加
<script>
let stu3 = {};
stu3.name = "李四";
stu3.courses = [];
stu3.addCourse = function(courseId, courseName) {
let courseObj = {};
courseObj[courseId] = courseName;
this.courses.push(courseObj);
};
stu3.addCourse("001", "高等数学");
stu3.addCourse("002", "Java");
stu3.addCourse("003", "JS");
</script>
阅读全文