14_对象.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. // var person = {
  12. // name: 'zs',
  13. // age: 18,
  14. // school: {
  15. // num: 10000,
  16. // name: 'qinghua'
  17. // }
  18. // }
  19. // console.log(person.age)
  20. var computer = new Object();
  21. //对象.属性名 = 属性值
  22. computer.cpu = 'i9-13'
  23. computer.xianka = '4090'
  24. computer.neicun = 'sanxing16G'
  25. console.log(computer)
  26. var person = new Array();
  27. person[0] = 18;
  28. person[1] = "123kg";
  29. person[2] = "170cm";
  30. person[3] = 2;
  31. console.log(person)
  32. console.log(typeof computer) //数组还是对象 数据类型都是object
  33. console.log(typeof person)
  34. var x = new String(); // 把 x 声明为 String 对象
  35. var y = new Number(); // 把 y 声明为 Number 对象
  36. var z = new Boolean(); // 把 z 声明为 Boolean 对象
  37. x = '123'
  38. // 请避免字符串、数值或逻辑对象。他们会增加代码的复杂性并降低执行速度
  39. </script>
  40. </body>
  41. </html>