Bản đồ là tập hợp các mục dữ liệu có khóa, giống như một
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
5. Nhưng sự khác biệt chính là let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 cho phép các loại khóaCác phương thức và thuộc tính là
7 – tạo bản đồlet john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
8 – lưu trữ giá trị bằng khóalet john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
9 – trả về giá trị theo khóa,let john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
0 nếulet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
1 không tồn tại trên bản đồlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
2 – trả vềlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
3 nếu tồn tạilet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
1, ngược lại làlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
5let john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
6 – xóa phần tử [cặp khóa/giá trị] bằng khóalet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
7 – xóa mọi thứ khỏi bản đồlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
8 – trả về số lượng phần tử hiện tạilet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
Ví dụ
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
4Như chúng ta có thể thấy, không giống như các đối tượng, các khóa không được chuyển thành chuỗi. Bất kỳ loại chìa khóa là có thể
9 không phải là cách đúng đắn để sử dụng let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
3let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
Mặc dù
let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
9 cũng hoạt động, e. g. chúng ta có thể đặt let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
82, điều này đang coi let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
83 là một đối tượng JavaScript đơn giản, do đó, nó bao hàm tất cả các giới hạn tương ứng [chỉ các khóa chuỗi/ký hiệu, v.v.]Vì vậy, chúng ta nên sử dụng phương pháp
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
83. let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
85, let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
86, v.v.Bản đồ cũng có thể sử dụng các đối tượng làm chìa khóa
Ví dụ
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
Sử dụng các đối tượng làm chìa khóa là một trong những tính năng quan trọng và đáng chú ý nhất của
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3. Điều tương tự không được tính cho let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
5. Chuỗi làm khóa trong let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
5 cũng được, nhưng chúng tôi không thể sử dụng một let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
5 khác làm khóa trong let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
5Hãy thử
let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
Vì
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
02 là một đối tượng, nó chuyển đổi tất cả các khóa let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
5, chẳng hạn như let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
04 và let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
05 ở trên, thành cùng một chuỗi let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
06. Chắc chắn không phải những gì chúng ta muốnCách
3 so sánh các khóalet john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
Để kiểm tra tính tương đương của các khóa,
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 sử dụng thuật toán SameValueZero. Nó gần giống với đẳng thức nghiêm ngặt let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
09, nhưng điểm khác biệt là ________ 380 được coi là bằng với ________ 380. Vì vậy, let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
80 cũng có thể được sử dụng làm khóaThuật toán này không thể thay đổi hoặc tùy chỉnh
xiềng xích
Mỗi cuộc gọi
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
83 đều trả về bản đồ, vì vậy chúng tôi có thể "xâu chuỗi" các cuộc gọilet john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
8Lặp lại trên Bản đồ
Để lặp qua một
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
83, có 3 phương pháp
85 – trả về một lần lặp cho các khóa,let john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
86 – trả về một giá trị có thể lặp lại,let john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
87 – trả về một lần lặp cho các mục nhậplet john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
88, nó được sử dụng theo mặc định tronglet john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
89let john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
Ví dụ
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
0Thứ tự chèn được sử dụng
Việc lặp đi lặp lại theo thứ tự như các giá trị đã được chèn vào.
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 duy trì thứ tự này, không giống như một let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
5 thông thườngBên cạnh đó,
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 có phương thức let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
33 tích hợp, tương tự như let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
34let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
8Sự vật. mục. Bản đồ từ đối tượng
Khi một
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 được tạo, chúng ta có thể truyền một mảng [hoặc một mảng khác có thể lặp lại] với các cặp khóa/giá trị để khởi tạo, như thế nàylet john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
3Nếu chúng ta có một đối tượng đơn giản và chúng ta muốn tạo một
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 từ nó, thì chúng ta có thể sử dụng phương thức tích hợp sẵn Object. các mục [obj] trả về một mảng các cặp khóa/giá trị cho một đối tượng chính xác ở định dạng đóVì vậy, chúng ta có thể tạo bản đồ từ một đối tượng như thế này
let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
9Ở đây,
let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
37 trả về mảng các cặp khóa/giá trị. let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
38. Đó là những gì let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 cầnSự vật. fromEntries. Đối tượng từ Bản đồ
Chúng ta vừa xem cách tạo
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 từ một đối tượng đơn giản với let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
91Có phương thức
let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
92 thực hiện ngược lại. đưa ra một mảng gồm các cặp let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
88, nó tạo ra một đối tượng từ chúnglet john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
7Chúng ta có thể sử dụng
let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
92 để lấy một đối tượng đơn giản từ let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3E. g. chúng tôi lưu trữ dữ liệu trong một
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3, nhưng chúng tôi cần chuyển dữ liệu đó tới mã của bên thứ 3 mong đợi một đối tượng đơn giảnchúng ta đi đây
let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
1Một cuộc gọi đến
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
87 trả về một cặp khóa/giá trị có thể lặp lại, chính xác ở định dạng phù hợp cho let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
92Chúng tôi cũng có thể làm cho dòng
let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
99 ngắn hơnlet john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
0Điều đó cũng tương tự, bởi vì
let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
92 mong đợi một đối tượng có thể lặp lại làm đối số. Không nhất thiết phải là một mảng. Và phép lặp tiêu chuẩn cho let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
83 trả về các cặp khóa/giá trị giống như let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
87. Vì vậy, chúng tôi nhận được một đối tượng đơn giản có cùng khóa/giá trị như let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
83Bộ
Một
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
4 là một tập hợp loại đặc biệt – “tập hợp các giá trị” [không có khóa], trong đó mỗi giá trị chỉ có thể xuất hiện một lầnphương pháp chính của nó là
75 – tạo tập hợp và nếu một đối tượnglet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
76 được cung cấp [thường là một mảng], hãy sao chép các giá trị từ đối tượng đó vào tập hợplet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
77 – thêm một giá trị, trả về chính tập hợp đólet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
78 – loại bỏ giá trị, trả vềlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
3 nếulet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
10 tồn tại tại thời điểm gọi, nếu không thìlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
5let john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
12 – trả vềlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
3 nếu giá trị tồn tại trong tập hợp, nếu không thìlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
5let john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
15 – loại bỏ mọi thứ khỏi bộlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
16 – là số nguyên tốlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
Tính năng chính là các cuộc gọi lặp đi lặp lại của
let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
77 với cùng một giá trị không làm gì cả. Đó là lý do tại sao mỗi giá trị chỉ xuất hiện trong một let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
4 một lầnVí dụ: chúng tôi có khách đến và chúng tôi muốn ghi nhớ tất cả mọi người. Nhưng các lượt truy cập lặp đi lặp lại sẽ không dẫn đến trùng lặp. Một khách truy cập phải được "đếm" một lần duy nhất
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
4 chỉ là điều phù hợp cho điều đólet john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
1Giải pháp thay thế cho
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
4 có thể là một mảng người dùng và mã để kiểm tra các bản sao trên mỗi lần chèn bằng cách sử dụng mảng. tìm thấy. Nhưng hiệu suất sẽ tệ hơn nhiều, bởi vì phương pháp này đi qua toàn bộ mảng kiểm tra mọi phần tử. let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
4 được tối ưu hóa nội bộ tốt hơn nhiều để kiểm tra tính duy nhấtLặp lại Set
Chúng ta có thể lặp qua một tập hợp bằng
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
89 hoặc bằng cách sử dụng let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
33let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
2Lưu ý điều buồn cười. Hàm gọi lại được truyền trong
let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
33 có 3 đối số. một let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
10, sau đó là cùng một giá trị let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
06 và sau đó là đối tượng đích. Thật vậy, cùng một giá trị xuất hiện trong các đối số hai lầnĐó là khả năng tương thích với
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 khi cuộc gọi lại được thông qua let john = { name: "John" };
let ben = { name: "Ben" };
let visitsCountObj = {}; // try to use an object
visitsCountObj[ben] = 234; // try to use ben object as the key
visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced
// That's what got written!
alert[ visitsCountObj["[object Object]"] ]; // 123
33 có ba đối số. Trông hơi lạ, chắc chắn. Nhưng điều này có thể giúp thay thế let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 bằng let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
4 trong một số trường hợp một cách dễ dàng và ngược lạiCác phương pháp tương tự mà
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 dành cho các trình vòng lặp cũng được hỗ trợ
12 – trả về một đối tượng có thể lặp lại cho các giá trị,let john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
13 – giống nhưlet john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
12, để tương thích vớilet john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
3,let john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
16 – trả về một đối tượng có thể lặp lại cho các mục nhậplet john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
17, tồn tại để tương thích vớilet john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
3let john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
Bản tóm tắt
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 – là tập hợp các giá trị được khóaPhương thức và thuộc tính
20 – tạo bản đồ, với tùy chọnlet john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
76 [e. g. mảng] củalet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
22 cặp để khởi tạolet john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
8 – lưu trữ giá trị theo khóa, trả về chính bản đồlet john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
9 – trả về giá trị theo khóa,let john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
0 nếulet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
1 không tồn tại trên bản đồlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
2 – trả vềlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
3 nếu tồn tạilet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
1, ngược lại làlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
5let john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
6 – loại bỏ phần tử bằng phím, trả vềlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
3 nếulet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
1 tồn tại tại thời điểm gọi, nếu không thìlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
5let john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
7 – xóa mọi thứ khỏi bản đồlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
8 – trả về số lượng phần tử hiện tạilet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
Sự khác biệt so với một
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
5 thông thường- Bất kỳ chìa khóa, đồ vật nào cũng có thể là chìa khóa
- Các phương pháp thuận tiện bổ sung, thuộc tính
38let john = { name: "John" }; // for every user, let's store their visits count let visitsCountMap = new Map[]; // john is the key for the map visitsCountMap.set[john, 123]; alert[ visitsCountMap.get[john] ]; // 123
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
4 – là một tập hợp các giá trị duy nhấtPhương thức và thuộc tính
75 – tạo tập hợp, với tùy chọnlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
76 [e. g. mảng] của các giá trị để khởi tạolet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
77 – thêm một giá trị [không làm gì nếulet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
10 tồn tại], trả về chính tập hợp đólet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
78 – loại bỏ giá trị, trả vềlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
3 nếulet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
10 tồn tại tại thời điểm gọi, nếu không thìlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
5let john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
12 – trả vềlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
3 nếu giá trị tồn tại trong tập hợp, nếu không thìlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
5let john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
15 – loại bỏ mọi thứ khỏi bộlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
16 – là số nguyên tốlet john = { name: "John" }; let ben = { name: "Ben" }; let visitsCountObj = {}; // try to use an object visitsCountObj[ben] = 234; // try to use ben object as the key visitsCountObj[john] = 123; // try to use john object as the key, ben object will get replaced // That's what got written! alert[ visitsCountObj["[object Object]"] ]; // 123
Việc lặp lại trên
let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
3 và let john = { name: "John" };
// for every user, let's store their visits count
let visitsCountMap = new Map[];
// john is the key for the map
visitsCountMap.set[john, 123];
alert[ visitsCountMap.get[john] ]; // 123
4 luôn theo thứ tự chèn, vì vậy chúng tôi không thể nói rằng các tập hợp này không có thứ tự, nhưng chúng tôi không thể sắp xếp lại các phần tử hoặc lấy trực tiếp một phần tử theo số của nó