Skip to content

Commit

Permalink
update(JS): web/javascript/reference/global_objects/array/map
Browse files Browse the repository at this point in the history
  • Loading branch information
undead404 authored and AdriandeCita committed Nov 7, 2022
1 parent 2efa585 commit ff4d605
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ const kvArray = [
];

const reformattedArray = kvArray.map(({ key, value }) => ({ [key]: value }));
// reformattedArray тепер [{1: 10}, {2: 20}, {3: 30}],

// kvArray залишається таким:
// [{key: 1, value: 10},
// {key: 2, value: 20},
// {key: 3, value: 30}]
console.log(reformattedArray); // [{ 1: 10 }, { 2: 20 }, { 3: 30 }]
console.log(kvArray);
// [
// { key: 1, value: 10 },
// { key: 2, value: 20 },
// { key: 3, value: 30 }
// ]
```

### Перебирання масиву чисел із застосуванням функції з аргументом
Expand All @@ -120,8 +122,8 @@ const reformattedArray = kvArray.map(({ key, value }) => ({ [key]: value }));
const numbers = [1, 4, 9];
const doubles = numbers.map((num) => num * 2);

// doubles тепер [2, 8, 18]
// numbers залишається [1, 4, 9]
console.log(doubles); // [2, 8, 18]
console.log(numbers); // [1, 4, 9]
```

### Виклик map() на об'єктах-немасивах
Expand Down

0 comments on commit ff4d605

Please sign in to comment.