Skip to content

Commit 1398770

Browse files
committed
translated until line 231
1 parent e942b5c commit 1398770

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

1-js/05-data-types/07-map-set/article.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ map.set('1', 'str1'); // o cheie string
3131
map.set(1, 'num1'); // o cheie numerică
3232
map.set(true, 'bool1'); // o cheie boolean
3333

34-
// vă amintiți de obiectul obișnuit Object? acesta ar converti cheile în șiruri de caractere
34+
// vă amintiți de Obiectul obișnuit? acesta ar converti cheile în șiruri de caractere
3535
// Map păstrează tipul, deci acestea două sunt diferite:
3636
alert( map.get(1) ); // 'num1'
3737
alert( map.get('1') ); // 'str1'
@@ -42,7 +42,7 @@ alert( map.size ); // 3
4242
După cum putem vedea, spre deosebire de obiecte, cheile nu sunt convertite în șiruri de caractere. Orice tip de cheie este posibilă.
4343

4444
```smart header="`map[key]` nu este modalitatea corectă de utilizare a unui `Map`"
45-
Deși `map[key]` funcționează de asemenea, e.g. putem seta `map[key] = 2`, acest lucru tratează `map` ca pe un simplu obiect JavaScript, deci implică toate limitările corespunzătoare (numai chei de tip string/simbol și așa mai departe).
45+
Deși `map[key]` funcționează de asemenea, e.g. putem seta `map[key] = 2`, acest lucru tratează `map` ca pe un obiect obișnuit JavaScript, deci implică toate limitările corespunzătoare (numai chei de tip string/simbol și așa mai departe).
4646

4747
Deci ar trebui să folosim metodele `map`: `set`, `get` și așa mai departe.
4848
```
@@ -161,9 +161,9 @@ let map = new Map([
161161
alert( map.get('1') ); // str1
162162
```
163163
164-
If we have a plain object, and we'd like to create a `Map` from it, then we can use built-in method [Object.entries(obj)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries) that returns an array of key/value pairs for an object exactly in that format.
164+
Dacă avem un obiect obișnuit, și dorim să creăm un `Map` din el, atunci putem folosi metoda încorporată [Object.entries(obj)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries) care returnează o matrice de perechi cheie/valoare pentru un obiect exact în acest format.
165165
166-
So we can create a map from an object like this:
166+
Astfel putem crea un map dintr-un obiect în felul următor:
167167
168168
```js run
169169
let obj = {
@@ -178,14 +178,14 @@ let map = new Map(Object.entries(obj));
178178
alert( map.get('name') ); // John
179179
```
180180
181-
Here, `Object.entries` returns the array of key/value pairs: `[ ["name","John"], ["age", 30] ]`. That's what `Map` needs.
181+
Aici, `Object.entries` returnează matricea de perechi cheie/valoare: `[ ["name","John"], ["age", 30] ]`. De asta are nevoie `Map`.
182182
183183
184-
## Object.fromEntries: Object from Map
184+
## Object.fromEntries: Obiect din Map
185185
186-
We've just seen how to create `Map` from a plain object with `Object.entries(obj)`.
186+
Tocmai am văzut cum să creăm `Map` dintr-un obiect obișnuit cu `Object.entries(obj)`.
187187
188-
There's `Object.fromEntries` method that does the reverse: given an array of `[key, value]` pairs, it creates an object from them:
188+
Există metoda `Object.fromEntries` care face invers: primind o matrice de perechi `[key, value]`, aceasta creează un obiect din ele:
189189
190190
```js run
191191
let prices = Object.fromEntries([
@@ -194,16 +194,16 @@ let prices = Object.fromEntries([
194194
['meat', 4]
195195
]);
196196
197-
// now prices = { banana: 1, orange: 2, meat: 4 }
197+
// acum prices = { banana: 1, orange: 2, meat: 4 }
198198
199199
alert(prices.orange); // 2
200200
```
201201
202-
We can use `Object.fromEntries` to get a plain object from `Map`.
202+
Putem folosi `Object.fromEntries` pentru a obține un obiect obișnuit din `Map`.
203203
204-
E.g. we store the data in a `Map`, but we need to pass it to a 3rd-party code that expects a plain object.
204+
E.g. stocăm datele într-un `Map`, dar trebuie să le transmitem unui cod terț care așteaptă un obiect obișnuit.
205205
206-
Here we go:
206+
Iată cum procedăm:
207207
208208
```js run
209209
let map = new Map();
@@ -212,23 +212,23 @@ map.set('orange', 2);
212212
map.set('meat', 4);
213213
214214
*!*
215-
let obj = Object.fromEntries(map.entries()); // make a plain object (*)
215+
let obj = Object.fromEntries(map.entries()); // face un obiect obișnuit (*)
216216
*/!*
217217
218-
// done!
218+
// gata!
219219
// obj = { banana: 1, orange: 2, meat: 4 }
220220
221221
alert(obj.orange); // 2
222222
```
223223
224-
A call to `map.entries()` returns an iterable of key/value pairs, exactly in the right format for `Object.fromEntries`.
224+
Un apel către `map.entries()` returnează un iterabil de perechi cheie/valoare, exact în formatul corect pentru `Object.fromEntries`.
225225
226-
We could also make line `(*)` shorter:
226+
Am putea de asemenea să facem linia `(*)` mai scurtă:
227227
```js
228228
let obj = Object.fromEntries(map); // omit .entries()
229229
```
230230
231-
That's the same, because `Object.fromEntries` expects an iterable object as the argument. Not necessarily an array. And the standard iteration for `map` returns same key/value pairs as `map.entries()`. So we get a plain object with same key/values as the `map`.
231+
Este același lucru, deoarece `Object.fromEntries` așteaptă ca argument un obiect iterabil. Nu neapărat o matrice. Iar iterația standard pentru `map` returnează aceleași perechi cheie/valoare ca și `map.entries()`. Deci obținem un obiect obișnuit cu aceleași chei/valori ca și `map`.
232232
233233
## Set
234234

0 commit comments

Comments
 (0)