Blogger Information
Blog 28
fans 0
comment 0
visits 11631
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
11.2日作业
子墨吖ฅฅ
Original
306 people have browsed it
  1. // 1.一维数组
  2. const arr = [1,2,3,4,5]
  3. console.log(arr[0],arr[4]);
  4. // 2.多维数组 (成员还是数组)
  5. const arr1 = [
  6. [1,2,3,4,5],
  7. [6,7,8,9,10],
  8. ['手机','电脑','电视']
  9. ]
  10. console.log(arr1[2][1]);
  11. // 3.对象数组 (成员是对象)
  12. // 通常用于 前后端交互 返回的json对象
  13. const arr2 = [
  14. {
  15. name: "张三",
  16. age: 18
  17. },
  18. {
  19. name: "李四",
  20. age: 20
  21. },
  22. {
  23. name: "小红",
  24. age: 19
  25. }
  26. ]
  27. console.log(arr2[2].name);
  28. // 4 .类数组 (仍然是一个对象, 只是用对象来模拟一个数组)
  29. // 1. 由0开始的递增的正整数的索引/属性
  30. // 2. 必须要有 `length`,表示成员数量/数组长度
  31. const arr3 = {
  32. 0: 'admin',
  33. 1: 'admin@qq.com',
  34. 2: '123456',
  35. length: 3
  36. }
  37. console.log(typeof arr3);// 可以看到输出的是object 我在用Array.isArray检测一下
  38. console.log(Array.isArray(arr3)); //这是任然不是数组
  39. console.log(Array.from(arr3)); //用array.from转成了数组 arr3就变成了一个简单的一维数组
  40. console.log(arr3[0]);
  41. // ----------------------------------------------------------
  42. // 1.单分支
  43. if(true){
  44. console.log(1);
  45. }
  46. // 2.双分支 可以用三元简化
  47. let status = true ;
  48. if(status){
  49. console.log("success");
  50. }else{
  51. console.log("failed");
  52. }
  53. // 简化方式
  54. let result = status ? 'success' : 'failed'
  55. // 判断?成功执行:失败执行
  56. console.log(result);
  57. // 3.多分支(switch)
  58. let score = -50;
  59. if(score >= 80 && score <= 100){
  60. console.log("优秀");
  61. }else{
  62. if( score >= 70 && score < 80){
  63. console.log("良好");
  64. }else{
  65. if(score >= 60 && score < 70){
  66. console.log("及格");
  67. }else{
  68. if(score > 0 && score < 60){
  69. console.log("不及格");
  70. }else{
  71. console.log("数据异常");
  72. }
  73. }
  74. }
  75. }
  76. // 这时用switch就很简单
  77. switch (score) {
  78. case score >= 80 && score <= 100:
  79. console.log("优秀");
  80. break;
  81. case score >= 70 && score < 80:
  82. console.log("良好");
  83. break;
  84. case score >= 60 && score < 70:
  85. console.log("及格");
  86. break;
  87. case score > 0 && score < 60:
  88. console.log("不及格");
  89. break;
  90. default:
  91. console.log("数据异常")
  92. break;
  93. }

运行图

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:作业一直都完成的很好, 并且及时
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post