5.对象.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // 生成新的空数组
  2. var arr = new Array();
  3. var arr = [];
  4. // 生成新的空对象
  5. var obj2 = new Object();
  6. var aa = {}
  7. // var data = new Date();
  8. // console.log(data,'data')
  9. obj2.name = '我的';
  10. console.log(obj2,'obj2');
  11. // 创建一个对象 对象的声明
  12. var obj1 = {};
  13. var obj = {
  14. name: '小郑',
  15. sex: '女',
  16. age: '我不告诉你'
  17. }
  18. // 对象的使用
  19. // 对象名.属性名 = 属性值
  20. console.log(obj.name);
  21. console.log(arr);
  22. function fn1() {
  23. console.log("这是一个函数")
  24. }
  25. console.log(typeof fn1(),'打印函数')
  26. console.log(typeof arr,'打印数组');//Object
  27. console.log(typeof obj,"打印对象");//Object
  28. var x = new String(); // 把 x 声明为 String 对象
  29. var y = new Number(); // 把 y 声明为 Number 对象
  30. var z = new Boolean(); // 把 z 声明为 Boolean 对象
  31. // 请避免字符串、数值或逻辑对象。他们会增加代码的复杂性并降低执行速度。
  32. var aa = 1;
  33. console.log(typeof aa);
  34. console.log(typeof x,'x');
  35. console.log(typeof y,'y');
  36. console.log(typeof z,'z')
  37. console.log( x,'x1');
  38. console.log( y,'y1');
  39. console.log( z,'z1')
  40. var arr=new Array();
  41. var a;
  42. var b;
  43. var obj={
  44. name:'cheny',
  45. age:13,
  46. active:function fn1(a1,b1){
  47. a = a1+b1;
  48. return console.log(a)
  49. }
  50. }
  51. obj["active"](1,2)
  52. // continue
  53. // for
  54. var c1 = 11;
  55. while(c1 <= 15){
  56. c1++;
  57. if( c1 == 13 ) {
  58. continue;
  59. }
  60. document.write(c1);
  61. }