JS内部对象
5内部对象
标准对象
typeof 123
"number"
typeof '123'
"string"
typeof true
"boolean"
typeof NaN
"number"
typeof []
"object"
typeof {}
"object"
typeof Map
"function"
typeof undefined
"undefined"
5.1 Date
let now = new Date();//Date Fri Mar 12 2021 22:20:11 GMT+0800 (中国标准时间)
now.getFullYear(); //年
now.getMonth(); //月
now.getDate(); //日
now.getDay(); //星期几
now.getHours() //时
now.getMinutes() //分
now.getSeconds() //秒
now.getTime();//时间戳 全世界统一 1970 1-1 0:00:00 毫秒数
5.2 JSON
json是什么
早期,所有数据传输习惯使用XML文件!
- 是一种经量级的数据交换格式。
- 简洁和清晰的层次结构使得JSON成为理想的数据交换语言。
- 易于阅读和编写,同时也易于机器解析和生成,并有效地提升网络传输效率。
在JavaScript一切皆为对象,任何js支持的类型都可以用JSON来表示。
格式:
- 对象都用{}
- 数组都用[]
- 所有的键值对都用key:value
//JSON字符串和JS对象的转化
let user = {
name: "xiao",
age: 3,
sex:"男生"
}
//对象转化为json字符串{"name":"xiao","age":3,"sex":"男生"
let jsonUser = JSON.stringify(user);
//json 字符串转化为对象, 参数为json字符串
//var obj = JSON.parse('{"name":"xiao","age":3,"sex":"男生"}');
JSON和JS对象的区别
var obj = {a:'hello',b:'heeel'};
var json = {"a":"hello","b":"hell"};
5.3 Ajax
- 原生的js写法 xhr异步请求
- jQuey封装好的方法 $("#name").ajax("")
- axios 请求
转载https://www.cnblogs.com/cyjy/p/6428908.html

浙公网安备 33010602011771号