内部对象

标准对象

typeof 123
"number"
typeof "123"
"string"
typeof true
"boolean"
typeof NaN
"number"
typeof []
"object"
typeof {
    
    }
"object"
typeof Math.floor
"function"
typeof undefined
"undefined"

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  毫秒数
        console.log(new Date(1610541401858))//时间戳转为时间

转换:

now=new Date(1610541401858)
Wed Jan 13 2021 20:36:41 GMT+0800 (中国标准时间)
now.toLocaleString()
"2021/1/13 下午8:36:41"
now.toGMTString()
"Wed, 13 Jan 2021 12:36:41 GMT"

JSON:
在JS中一切皆为对象,任何JS支持的类型都可以用JSON来表示
格式:
对象都用{ }
数组都用[ ]
所有的键值对都使用key : value

JSON字符串和JS对象的转换:

var user={
    
    
    name:"Dai",
    age:"16",
    sex:"男"
}

//对象转化为JSON字符串   '{"name":"Dai","age":"16","sex":"男"}'
var jsonUser = JSON.stringify(user)

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

猜你喜欢

转载自blog.csdn.net/weixin_47620760/article/details/113941824