You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/05-data-types/07-map-set/article.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,49 +49,49 @@ Deci ar trebui să folosim metodele `map`: `set`, `get` și așa mai departe.
49
49
50
50
**Map poate folosi și obiecte ca și chei.**
51
51
52
-
For instance:
52
+
De exemplu:
53
53
54
54
```js run
55
55
let john = { name: "John" };
56
56
57
-
// for every user, let's store their visits count
57
+
// pentru fiecare utilizator, să stocăm numărul de vizite ale acestuia
58
58
let visitsCountMap = new Map();
59
59
60
-
// john is the key for the map
60
+
// john este cheia pentru hartă
61
61
visitsCountMap.set(john, 123);
62
62
63
63
alert( visitsCountMap.get(john) ); // 123
64
64
```
65
65
66
-
Using objects as keys is one of the most notable and important `Map` features. The same does not count for `Object`. String as a key in `Object`is fine, but we can't use another `Object`as a key in`Object`.
66
+
Utilizarea obiectelor drept chei este una dintre cele mai notabile și importante caracteristici ale `Map`. Același lucru nu se pune la socoteală pentru `Object`. String ca cheie în `Object`este în regulă, dar nu putem folosi un alt `Object`drept cheie în`Object`.
67
67
68
-
Let's try:
68
+
Să încercăm:
69
69
70
70
```js run
71
71
let john = { name:"John" };
72
72
let ben = { name:"Ben" };
73
73
74
-
let visitsCountObj = {}; //try to use an object
74
+
let visitsCountObj = {}; //încercați să folosiți un obiect
75
75
76
-
visitsCountObj[ben] =234; //try to use ben object as the key
77
-
visitsCountObj[john] =123; //try to use john object as the key, ben object will get replaced
76
+
visitsCountObj[ben] =234; //încercați să folosiți obiectul ben ca și cheie
77
+
visitsCountObj[john] =123; //încercați să utilizați obiectul john ca cheie, obiectul ben va fi înlocuit.
As`visitsCountObj`is an object, it converts all `Object` keys, such as `john`and`ben`above, to same string `"[object Object]"`. Definitely not what we want.
85
+
Deoarece`visitsCountObj`este un obiect, acesta convertește toate cheile `Object`, cum ar fi `john`și`ben`de mai sus, în același șir de caractere `"[object Object]"`. Cu siguranță nu este ceea ce ne dorim.
86
86
87
-
```smart header="How `Map`compares keys"
88
-
To test keys for equivalence, `Map`uses the algorithm [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero). It is roughly the same as strict equality `===`, but the difference is that `NaN`is considered equal to`NaN`. So`NaN`can be used as the key as well.
87
+
```smart header="Cum compară `Map`cheile"
88
+
Pentru a testa echivalența cheilor, `Map`folosește algoritmul [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero). Este aproximativ la fel ca egalitatea strictă `===`, dar diferența este că `NaN`este considerat egal cu`NaN`. Astfel`NaN`poate fi folosit și ca cheie de asemenea.
89
89
90
-
This algorithm can't be changed or customized.
90
+
Acest algoritm nu poate fi modificat sau personalizat.
91
91
```
92
92
93
-
````smart header="Chaining"
94
-
Every `map.set` call returns the map itself, so we can "chain" the calls:
93
+
````smart header="Înlănțuire"
94
+
Fiecare apel `map.set` returnează map însăși, astfel încât putem "înlănțui" apelurile:
0 commit comments