JS Object的用法

katesharing發表於2024-08-15

讀取屬性的方法記一下

//js object的寫法
    const person = {
        firstName: "John",
        lastName: "Doe",
        age: 50,
        eyeColor: "blue",
        fullName: function () {
            return this.firstName + " " + this.lastName;
        }
    };
    //獲取object的屬性方法
    //法一:
    console.log("法一:",person.firstName);
    //法二:
    console.log("法二:",person["firstName"]);

相關文章