内部对象(JavaScript)

suaxi
2020-12-09 / 0 评论 / 74 阅读 / 正在检测是否收录...
标准对象
typeof 123
"number"
typeof '123'
"string"
typeof NaN
"number"
typeof true
"boolean"
typeof []
"object"
typeof {}
"object"
typeof Math.abs
"function"
typeof undefined
"undefined"

1.1 Date

基本使用

var now = new Date();
now.getFullYear(); //年
now.getMonth(); //月
now.getDate(); //日
now.getDay(); //星期几
now.getHours(); //时
now.getMinutes(); //分
now.getSeconds(); //秒
now.getTime(); //时间戳,从1970-01-01 0:00:00到现在的毫秒数(全世界统一)

console.log(new Date(1607479949417)); //时间戳转为当前时间

转换

now.toLocaleString //此处调用的是一个方法
ƒ toLocaleString() { [native code] }
now.toLocaleString()
"2020/12/9 上午10:16:59"
now.toGMTString()
"Wed, 09 Dec 2020 02:16:59 GMT"

1.2 JSON

json是什么
  • 是一种轻量级的数据交换格式
  • 层次结构简洁清晰
  • 易于阅读和编写,同时也易于机器解析和生成,并有效地提升网络传输效率

格式:

  • 对象都用 {}
  • 数组都用 []
  • 所有的键值对都用 key:value

json字符串和js对象的转化:

var user = {
    name: "孙笑川",
    age: 33,
    sex: '男'
}

//对象转化为json字符串 {"name":"孙笑川","age":33,"sex":"男"}
var jsonUser = JSON.stringify(user);

//json字符串转化为对象 参数为json字符串
var obj = JSON.parse('{"name":"孙笑川","age":33,"sex":"男"}');

1.3 Ajax

  • 原生的js写法 xhr
  • JQuery封装好的方法 $("name").ajax("")
  • axios 请求
0

评论 (0)

取消