Tham chiếu đối tượng JavaScript
Đối tượng JavaScript
Đối tượng là một trong những kiểu dữ liệu của JavaScript.
Các đối tượng được sử dụng để lưu trữ các bộ sưu tập khóa/giá trị (tên/giá trị).
Đối tượng JavaScript là một tập hợp các giá trị được đặt tên .
Ví dụ sau tạo một đối tượng JavaScript với bốn thuộc tính khóa/giá trị:
Ví dụ
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue"
};
Hãy tự mình thử »Để biết hướng dẫn về các đối tượng, hãy đọc Hướng dẫn về đối tượng JavaScript của chúng tôi.
Các phương thức và thuộc tính đối tượng JavaScript
Name | Description |
---|---|
assign() | Copies properties from a source object to a target object |
constructor | Returns the function that created an object's prototype |
create() | Returns a new object created from an existing objects prototype |
defineProperties() | Adds or changes properties |
defineProperty() | Adds or changes a property |
entries() | Returns an array of the key/value pairs of an object |
freeze() | Prevents any changes to an object |
fromEntries() | Returns an object created from an iterable list of key/value pairs |
getOwnPropertyDescriptor() | Returns an array of the keys of an object |
getOwnPropertyDescriptors() | Returns an array of the keys of an object |
getOwnPropertyNames() | Returns an array of the keys of an object |
groupBy() | Groups object elements according to returned callback values |
isExtensible() | Returns true if an object is extensible |
isFrozen() | Returns true if an object is frozen |
isSealed() | Returns true if an object is sealed |
keys() | Returns an array of the keys of an object |
preventExtensions() | Prevents adding new properties to an object |
prototype | Let you to add properties and methods to JavaScript objects |
seal() | Prevents adding new or deleting existing object properties |
toString() | Converts an object to a string and returns the result |
valueOf() | Returns the primitive value of an object |
values() | Returns an array of the property values of an object |