# .update()

### update(key, updateCallback)

| **Parameter**  | **Description**                                                                                                                             |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| key            | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></p><p>The target key</p>    |
| updateCallback | <p><a href="https://developer.mozilla.org/en-US/docs/Glossary/Callback_function">Callback</a></p><p>Function to call to update the data</p> |

| **Returns**                                                               | **Description**                               |
| ------------------------------------------------------------------------- | --------------------------------------------- |
| [JSONData](https://simpldb.gitbook.io/docs/types-and-interfaces/jsondata) | The updated data from the provided key's root |

####

```javascript
db.set('user', { name: 'Peter' }); // { name: 'Peter' }

db.update('user', (d) => d.name += "👨🏻‍💻"); // { name: 'Peter👨🏻‍💻' }
```

Also allows the use of dot notation:

```javascript
db.get('user'); // { name: '5antos' }

db.update('user.name', (d) => d = d.toUpperCase()); // { name: '5ANTOS' }
```

And even a way to delete a key from the data:

```javascript
db.get('person'); // { name: 'Peter', age: 19 }

db.update('person', (d) => delete d.age); // { name: 'Peter' } 
```

{% hint style="info" %}
When the callback parameter's value is not an object, the value that the update callback returns will be the value that will replace the old one, so it's optional to redefine its value inside the callback:
{% endhint %}

```javascript
db.get('user'); // { name: '5ANTOS' }

db.update('user.name', (d) => d = d.toLowerCase()); // { name: '5antos' }
// is the same as
db.update('user.name', (d) => d.toLowerCase()); // { name: '5antos' }
```
