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"]);
- var employees = [
- { "firstName":"Bill" , "lastName":"Gates" },
- { "firstName":"George" , "lastName":"Bush" },
- { "firstName":"Thomas" , "lastName": "Carter" }
- ];
- alert(employees[0].lastName); // 方式一
- alert(employees[0]["lastName"]); // 方式二