Objects and object properties

// If you want to record a simple variable data can be recorded digitally string Boolean;
// but if you want to record a message, but also contains this information (name Sex Age Student ID ...) is recommended to use object storage information;
// Object
(Object);
; ;
// EG student Object: attribute (name gender Age student
ID); ;
// create an object
format:; ;
// {property: property value, property: property value, property: attribute value};
;
// attributes: general said key button; the same variable names in the naming of the time;
;
// property value: commonly known value value; strings can also be numbers may be Boolean, it can be an object ;
;
// create an object literal manner: name age isMarried contains three
attributes;
; ;
var {=
K; ;
name: "HH",
;;
; ;
Age: 20 is ,;
;
isMarried: to
false; ;
};
;
// objects can also be () print object by the console.log; commonly used consoloe.dir () print object;
;
// the console.log (kangLiYuan) ;;
;
// console.dir (kangLiYuan) ;;
;
// The object property gets the value of the property;
;
the console.log (k.age);
;
the second embodiment // create objects;
;
var dogJinMao = {};
;
// object properties by adding attributes and attribute values.;
;
dogJinMao.name =
"golden"; ;
dogJinMao.age = 12
is; ;
dogJinMao.sex =
"F"; ;
the console.log
(dogJinMao); ;
. // object attribute property value can be
changed; ;
dogJinMao.age = 30 ;
;
the console.log
(dogJinMao); ;
// create an object when the object can be treated as a property;
;
var info = {;
;
name: "Big Head Son";
;
Age: 6 ,;
;
Father: {;
;
name: "first father" ;
;
Age:
30; ;
};
;
};
;
// nested objects when used in conjunction to find the corresponding property
value;. ;
the console.log
(info.father.age); ;
// Create an empty
object; ;
var } =
{Son; ;
son.name =
"Zha"; ;
son.age = 13 is;
V = {} // var
Father; ;
// father.name = "Li Jing";
// father.age = 30;
;
// // Father refers to the son of property

// son.father = father; // father objects

son.father = {

name: "Li Jing",

Age: 30
V}

the console.log (Son)

var Grade = {

name: "207",
Major: "Web",
teacher: "Yang"
}
V // by [] attribute string access attributes
console.log (grade [ "teacher"] )

Guess you like

Origin www.cnblogs.com/baixuezhemei/p/11597086.html