标准对象
typeof 123 'number' typeof '123' 'string' typeof true 'boolean' typeof NaN 'number' typeof [] 'object' typeof {} 'object' typeof Math.abs 'function' typeof undefined 'undefined'
基本使用
let now = new Date();//Fri Mar 11 2022 10:01:32 GMT+0800 (中国标准时间) now.getFullYear(); // 年 now.getMonth(); // 月 0~11 代表月 now.getDate(); //日 now.getDay(); //星期几 now.getHours(); //时 now.getMinutes(); //分 now.getSeconds(); // 秒 now.getTime(); //时间戳 全世界统一 1970.1.1 0:00:00 毫秒数 console.log(new Date(1646964539234)); // 时间戳转为时间 Fri Mar 11 2022 10:08:59 GMT+0800 (中国标准时间)
转换
now = new Date(1646964680935); Fri Mar 11 2022 10:11:20 GMT+0800 (中国标准时间) now.toLocaleString() //注意:调用是一个方法,不是属性 '2022/3/11 10:11:20' now.toGMTString() 'Fri, 11 Mar 2022 02:11:20 GMT'
json是什么
早期,所有数据传输习惯使用XML文件!
JSON(JavaScript Object Notation, JS 对象简谱) 是一种轻量级的数据交换格式
简洁和清晰的层次结构使得 JSON 成为理想的数据交换语言。
易于人阅读和编写,同时也易于机器解析和生成,并有效地提升网络传输效率。
在JavaScript一切皆为对象,任何js支持的类型都可以用JSON表示
格式:
对象都用{}
数组都用[]
所有的键值对 都是用key:value
json字符串和js对象的转化
let user = { name:"杨不悔", age:18, character:'终生不悔' } //对象转化为json字符串{"name":"杨不悔","age":18,"character":"终生不悔"} let jsonUser = JSON.stringify(user); //json字符串转化为对象 参数为json字符串 let obj = JSON.parse('{"name":"杨不悔","age":18,"character":"终生不悔"}');//里面是双引号 ,外面就不能用,反之亦然
很多人搞不清楚json字符串和js对象的区别
var obj = {name:"aaa",age:"18"} var json = '{"name":"aaa","age":"18"}'
原生的js写法 xhr 异步请求
jQuery 封装好的方法$("#name").ajax("")
axios 请求