<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <!--数据类型与对象--> <script> //数据类型 //数组有四种 var arr1 = new Array('a', 'b', 'c'); //预定数组初始化 var arr2 = ['a', 'b', 'c']; //同样是在创建时初始化,但是这种创建更为简洁直观 var arr3 = new Array(); var arr4 = []; //这两种是创建空的数组 //对象的创建,对象之间的属性要用逗号隔开, var peo={ name:"", age:12, eat:function(){ return:"蔬菜" }, eat:"汉堡", //如果对象中有两个重复的属性,那以后面的属性为准 } //创建新对象在附加属性 var people = new Object(); people.name = 'Tom'; people.age = 21; people.eat = function(){ } var one=people; console.log(one); console.log(one.age); console.log(peo.age); console.log(peo); //返回数据类型:typeof document.write(typeof people); //判断是否为数组 isArray,instanceof if(Array.isArray(peo)){ document.write("是数组"); } if(peo instanceof Array){ document.write("是数组"); } //利用toString()可以把数值转化为字符串 //与后端一致,如果对象值为空,aa为空那么.tostring()就会报错 var aa=100; var cc=aa.toString(); //利用parseInt()和parseFloat()可以把字符串转化为数值 var st="3.12"; var sti=parseInt(st); var stb=parseFloat(st); //null用于对象,undefined用于变量,属性与方法,对象被定义了位null,否则为undefined //获取对象属性:键值 Object.getOwnPropertyNames(peo); </script> </body> </html>
标签:people,对象,数据类型,JS,peo,数组,var From: https://www.cnblogs.com/H-Yan/p/16906968.html