Map.prototype.values()

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.

Phương thức values() của các instance Map trả về một đối tượng map iterator mới chứa các value cho mỗi phần tử trong map này theo thứ tự chèn.

Try it

const map = new Map();

map.set("0", "foo");
map.set(1, "bar");

const iterator = map.values();

console.log(iterator.next().value);
// Expected output: "foo"

console.log(iterator.next().value);
// Expected output: "bar"

Cú pháp

js
values()

Tham số

Không có.

Giá trị trả về

Một đối tượng iterator có thể lặp mới.

Ví dụ

Sử dụng values()

js
const myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");

const mapIter = myMap.values();

console.log(mapIter.next().value); // "foo"
console.log(mapIter.next().value); // "bar"
console.log(mapIter.next().value); // "baz"

Đặc tả kỹ thuật

Specification
ECMAScript® 2027 Language Specification
# sec-map.prototype.values

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

Xem thêm