批改状态:合格
老师批语:
/* 作业内容:1. 实例演示不同的数组类型与访问方式2. 实例演示分支的不同类型,注意else的本质*/// 一、实例演示不同的数组类型与访问方式// 1.创建有三个元素的数组console.log('-----------访问数组--------------')let arr1 = ['张三', '李四', '王五']// 访问:通过下标索引,从0开始console.log(arr1[0]) // 张三console.log(arr1[1]) // 李四console.log(arr1[2]) // 王五console.log('-----------多维数组--------------')// 2. 多维数组let listArry = [['张三', 33, true],['李四', 44, false],['王五', 55, null],]// 访问方式:console.log(listArry[0]) // [ '张三', 33, true ]console.log(listArry[1]) // [ '李四', 44, false ]console.log(listArry[2]) // [ '王五', 55, null ]// 原始遍历写法listArry.forEach(function (items, index){console.log(items, index)})// 遍历简写 去除function,只有一个参数时候去掉()括号,去掉returnlistArry.forEach((items) => console.log(items))console.log('-----------对象数组--------------')// 3.对象数组let StudentsList = [{ name: '张三', age: 25, wage: 500 },{ name: '李四', age: 35, wage: 2500 },{ name: '王五', age: 45, wage: 6500 },]StudentsList.forEach((items2) => console.log('对象数组访问方式:' + items2['name'] + '年龄:' + items2['age']))console.log('-----------类数组--------------')// 4.类数组let arr2 = {0: '张三',1: '李四',2: '王五',length: 3,}Array.from(arr2).forEach((items) => console.log('类数组访问方式:' + items))// 二、 实例演示分支的不同类型,注意else的本质console.log('-------------------------')// 单分支let a = 1 + 1if (a != 1) {console.log('等于2')}if (a != 1) {// 执行代码} else if (a != 2) {console.log('else if 就是 再如果')} else {console.log('else 就是 前面都不满足才执行')}let number = 6switch (number) {case 0:console.log('数字为0')breakcase 1:console.log('数字为1')breakcase 2:console.log('数字为2')breakcase 3:console.log('数字为3')breakcase 4:console.log('数字为4')breakcase 5:console.log('数字为5')breakdefault:console.log('非法输入')}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号