内部对象
typeof '123';
>"string"
typeof 123;
>"number"
typeof NaN;
>"number"
typeof true;
"boolean"
typeof undefined;
>"undefined"
typeof null;
>"object"
typeof Math.abs;
>"function"
typeof [];
"object"
Date
var now = new Date();
now.getFullYear();//年
now.getMonth();//月
now.getDate();//日
now.getDay();//星期
now.getHours();//时
now.getMinutes();//分
now.getMilliseconds();//秒
now.getTime();//时间戳
var time = new Date()
var time = new Date('时间戳');//将时间戳转化为标准时间
now.toLocaleString();//转化为当地时间
JSON
概念
JSON(JavaScript Object Notation, JS 对象简谱) 是一种轻量级的数据交换格式。
易于人阅读和编写,同时也易于机器解析和生成,并有效地提升网络传输效率。
简洁和清晰的层次结构使得 JSON 成为理想的数据交换语言。
定义
-
数据为 键/值 对。
-
数据由逗号分隔。
-
大括号保存对象
-
方括号保存数组
-
键/值对包括字段名称(在双引号中),后面一个冒号,然后是值
'{"name":"www","age":"10"}';//JSON {name:"www",age:10};//js对象
转化
var Person = {
name:'www',
age:10,
hobbies:['play', 'code', 'eat']
}
var json = JSON.stringify(Person);//将对象转化为JSON字符串
console.log(json);
>"{"name":"www","age":10,"hobbies":["play","code","eat"]}"
var obj = JSON.parse(json);//将JSON字符串转化为对象
console.log(obj);
>Object { name: "www", age: 10, hobbies: (3) […] }
如有不对的地方欢迎大家指出,共同进步!