Map.prototype.size

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Thuộc tính accessor size của các instance Map trả về số lượng phần tử trong map này.

Try it

const map = new Map();

map.set("a", "alpha");
map.set("b", "beta");
map.set("g", "gamma");

console.log(map.size);
// Expected output: 3

Mô tả

Giá trị của size là một số nguyên biểu diễn số mục mà đối tượng Map có. Hàm setter accessor cho sizeundefined; bạn không thể thay đổi thuộc tính này.

Ví dụ

Sử dụng size

js
const myMap = new Map();
myMap.set("a", "alpha");
myMap.set("b", "beta");
myMap.set("g", "gamma");

console.log(myMap.size); // 3

Đặc tả kỹ thuật

Specification
ECMAScript® 2027 Language Specification
# sec-get-map.prototype.size

Tương thích trình duyệt

Xem thêm