Skip to content
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions content/dart/concepts/map/terms/update-all/update-all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
Title: '.updateAll()'
Description: 'Updates all values in a map using a provided function.'
Subjects:
- 'Computer Science'
- 'Code Foundations'
Tags:
- 'Dart'
- 'Data Structures'
- 'Methods'
- 'Maps'
CatalogContent:
- 'learn-dart'
- 'paths/computer-science'
---

The **`.updateAll()`** method updates every value in a `Map` by applying a function to each key-value pair.

## Syntax

```pseudo
map.updateAll((key, value) => newValue);
```

**Parameters:**

- `key`: The current key in the map
- `value`: The current value associated with the key
- `newValue`: The value returned by the function, which replaces the existing value

**Return value:**

Returns `void`. The original map is modified in place.

## Example 1: Updating all values in a map

In this example, `.updateAll()` is used to apply a discount to all product prices stored in a map:

```dart
void main() {
Map<String, double> prices = {
'Laptop': 1000.0,
'Phone': 600.0,
'Tablet': 400.0
};

prices.updateAll((item, price) => price * 0.9);

print(prices);
}
```

The output of this code is:

```shell
{Laptop: 900, Phone: 540, Tablet: 360}
```

Each value in the map is passed to the update function, and the returned value replaces the original value while keeping the keys unchanged.