JavaScript对象属性访问的两种方式

JavaScript对象属性访问的两种方式

object.attribute

object["attribute"]

例如:

var employees = [
{ "firstName":"Bill" , "lastName":"Gates" },
{ "firstName":"George" , "lastName":"Bush" },
{ "firstName":"Thomas" , "lastName": "Carter" }
];
alert(employees[0].lastName);
alert(employees[0]["lastName"]);
  1. var employees = [
  2. { "firstName":"Bill" , "lastName":"Gates" },
  3. { "firstName":"George" , "lastName":"Bush" },
  4. { "firstName":"Thomas" , "lastName": "Carter" }
  5. ];
  6. alert(employees[0].lastName); // 方式一
  7. alert(employees[0]["lastName"]); // 方式二
上一篇:JavaScript对象属性的基础教程指南


下一篇:007-ant design 对象属性赋值,双向绑定