2022.4.13 js内部对象与json
3. 内部对象
标准对象
1 typeof 123 "number" 2 typeof '123' "string" 3 typeof true "boolean" 4 typeof NaN "number" 5 typeof [] "object" 6 typeof {} "object" 7 typeof Math.abs "function" 8 typeof undefined "undefined"
3.1 Date
基本使用
1 var now = new Date(); 2 console.log(now);//VM73:1 Tue Apr 12 2022 08:51:38 GMT+0800 (中国标准时间)现在的时间 3 now.getFu1TYear();//年 4 now.getMonth(); //月0~11代表月 5 now. getDate(); //日 6 now.getDay();//星期几 7 now.getHours();// 时 8 now. getMinutes();//分 9 now. getSeconds(); //秒 10 now.getTime();//时间戳全世界统一,从1970 1.1 0:00:00到现在的毫秒数 11 console.log(new Date(1649724698784))//时间戳转为时间 12  13 时间戳时间赋值给now 14 now = new Date(1649724698784);//Tue Apr 12 2022 08:51:38 GMT+0800 (中国标准时间) 星期二 四月 12号 2022 年 15 now.toLocaleString();//"2022/4/12 上午8:51:38" 本地时间
3.2 JSON
- 
JSON(JavaScript Object Notation,JS对象简谱)是一种轻量级的数据交换格式。 
- 
简洁和清晰的层次结构使得JSON成为理想的数据交换语言。 
- 
易于人阅读和编写,同时也易于机器解析和生成,并有效地提升网络传输效率。 
在JavaScript一切皆为对象、任何js支持的类型都可以用JSON来表示; number,string...
格式:
- 
对象都用{} 
- 
数组都用[] 
- 
所有的键值对 都是用key:value 
JSON字符串和JS对象的转化
1 var user = { 2 name:"jone", 3 age:20, 4 sex:"男" 5 } 6 //对象转化为json字符串 7 var jsonUser = JSON.stringify(user); 8 console.log(jsonUser);//{"name":"jone","age":20,"sex":"男"} 9 10 //json 字符串转化为对象 11 var obj = JSON.parse('{"name":"jone","age":20,"sex":"男"}');//单双引号要分开,里面双引号,外边单引号 12 console.log(obj);
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号