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
+17-17Lines changed: 17 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,13 +102,13 @@ map.set('1', 'str1')
102
102
103
103
## Iterare peste Map
104
104
105
-
For looping over a `map`, there are 3 methods:
105
+
Pentru a parcurge un `map`, există 3 metode:
106
106
107
-
- [`map.keys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys) -- returns an iterable for keys,
108
-
- [`map.values()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values) -- returns an iterable for values,
109
-
- [`map.entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries) -- returns an iterable for entries `[key, value]`, it's used by default in `for..of`.
107
+
- [`map.keys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys) -- returnează un iterabil pentru chei,
108
+
- [`map.values()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values) -- returnează un iterabil pentru valori,
109
+
- [`map.entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries) -- returnează un iterabil pentru intrările `[cheie, valoare]`, este utilizat în mod implicit în `for..of`.
110
110
111
-
For instance:
111
+
De exemplu:
112
112
113
113
```js run
114
114
let recipeMap = new Map([
@@ -117,41 +117,41 @@ let recipeMap = new Map([
117
117
['onion', 50]
118
118
]);
119
119
120
-
// iterate over keys (vegetables)
120
+
// iterați peste chei (vegetables)
121
121
for (let vegetable of recipeMap.keys()) {
122
122
alert(vegetable); // cucumber, tomatoes, onion
123
123
}
124
124
125
-
// iterate over values (amounts)
125
+
// iterați peste valori (amounts)
126
126
for (let amount of recipeMap.values()) {
127
127
alert(amount); // 500, 350, 50
128
128
}
129
129
130
-
// iterate over [key, value] entries
131
-
for (let entry of recipeMap) { // the same as of recipeMap.entries()
132
-
alert(entry); // cucumber,500 (and so on)
130
+
// iterați peste intrările [cheie, valoare]
131
+
for (let entry of recipeMap) { // același lucru ca și în recipeMap.entries()
132
+
alert(entry); // cucumber,500 (și așa mai departe)
133
133
}
134
134
```
135
135
136
-
```smart header="The insertion order is used"
137
-
The iteration goes in the same order as the values were inserted. `Map` preserves this order, unlike a regular `Object`.
136
+
```smart header="Se folosește ordinea de inserție"
137
+
Iterația se desfășoară în aceeași ordine în care au fost inserate valorile. `Map` păstrează această ordine, spre deosebire de un `Object` obișnuit.
138
138
```
139
139
140
-
Besides that, `Map` has a built-in `forEach` method, similar to `Array`:
140
+
Pe lângă asta, `Map` are o metodă încorporată `forEach`, similară cu `Array`:
141
141
142
142
```js
143
-
// runs the function for each (key, value) pair
143
+
// rulează funcția pentru fiecare pereche (cheie, valoare)
144
144
recipeMap.forEach( (value, key, map) => {
145
145
alert(`${key}: ${value}`); // cucumber: 500 etc
146
146
});
147
147
```
148
148
149
-
## Object.entries: Map from Object
149
+
## Object.entries: Map din Obiect
150
150
151
-
When a `Map` is created, we can pass an array (or another iterable) with key/value pairs for initialization, like this:
151
+
Când se creează un `Map`, putem transmite un array (sau un alt iterabil) cu perechi cheie/valoare pentru inițializare, astfel:
0 commit comments