Blogger Information
Blog 35
fans 0
comment 0
visits 16759
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组类型和分支演示
手机用户311660634
Original
296 people have browsed it
  1. // 1. 实例演示不同的数组类型与访问方式 2. 实例演示分支的不同类型,注意else的本质
  2. // 一维数组
  3. const arr1 = [
  4. 1, '华为', 'note8'
  5. ]
  6. console.log(arr1)
  7. // 多维数组
  8. const arr2 = [
  9. [1, '华为', 'note8'],
  10. [2, '小米', 'xiaomi10'],
  11. [3, '苹果', 'iphone14']
  12. ]
  13. console.log(arr2)
  14. // 对象数组
  15. const arr3 = [
  16. {id:1, name:'华为', xh:'note8'},
  17. {id:2, name:'小米', xh:'xiaomi10'},
  18. {id:3, name:'苹果', xh:'iphone14'}
  19. ]
  20. // 类数组
  21. const arr4 = {
  22. 0:'华为',
  23. 1:'小米',
  24. 2:'苹果',
  25. length:3
  26. }
  27. // 转换为真的数组 Array.from
  28. console.log(Array.from(arr4))
  29. // 单分支
  30. if(true){
  31. console.log('A');
  32. }
  33. // 双分支,三元简化
  34. let status = true;
  35. if(status){
  36. console.log("success")
  37. }else{
  38. console.log("failed")
  39. }
  40. // 简化方法
  41. let result = status ? 'success' : 'failed'
  42. // 多分枝
  43. let score = 55;
  44. switch(true){
  45. case score >= 80 && score <=100:
  46. console.log("优秀");
  47. break
  48. case score < 80 && score > 70:
  49. console.log("良好");
  50. break
  51. case score <70 && score > 60:
  52. console.log("合格");
  53. break
  54. case score <60 && score >0:
  55. console.log("不及格");
  56. default:
  57. console.log("错误")
  58. }
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