1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8">5 <title></title>6 <Scripttype= "Text/javascript">7 8 //Create an Object9 //var obj = new Object ();Ten One /* A * The above way is a bit cumbersome, there is a simpler way, essentially the same, both ways will be used - * Use object literals to create an object - */ the varobj= {}; - Console.log (typeofobj);//Object - - Obj.name= "Monkey King"; + Console.log (obj.name);//Monkey King - + //------------------------------------------------------------------------------------------------------ A at /* - * Using object literals, you can directly specify properties in an object when creating an object - * Syntax: {property Name: Property Value, Property name: Property value ....} - * The attribute name of the object literal can be quoted or not added, not recommended, - * If you want to use some special names, you must enclose them in quotation marks - * in * Property names and attribute values are a set of name-value pairs of structures, - * Use between name and value: Connect, use between multiple name pairs, separate to * If there is no other attribute after a property, do not write, + */ - the varObj2= { * $ Name:"Pig",Panax Notoginseng Age : -, - Gender:"male", the Test:{name:"Sand Monk"} + A }; the + Console.log (obj2.test);//Object Object - Console.log (obj2.test.name);//Sand Monk $ $ - </Script> - </Head> the <Body> - </Body>Wuyi </HTML>
JS Base _ Object literal