js访问对象的属性

var person = {
            firstName: "Bill",
            lastName: "Gates",
            age: 50,
            eyeColor: "blue"
        }
        console.log(person.firstName)        //Bill
        console.log(person['firstName'])     //Bill
        
        console.log(person.name)         //二者打印的的是一样的
        console.log(person['name'])      //没有的时候都undefined

猜你喜欢

转载自www.cnblogs.com/shun1015/p/12233069.html