2021-10-17 18:26:00 +02:00
|
|
|
---
|
2022-09-29 23:03:28 +02:00
|
|
|
title: Store.set()
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-29 23:03:28 +02:00
|
|
|
The `Store.set()` method stores the value of `value` in the store under key
|
|
|
|
`key`.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
|
|
|
```js
|
|
|
|
Store store.set(mixed key, mixed value)
|
|
|
|
```
|
|
|
|
|
2024-09-29 07:14:59 +02:00
|
|
|
:::tip
|
|
|
|
This method is chainable as it returns the `Store` object
|
|
|
|
:::
|
2022-09-29 23:03:28 +02:00
|
|
|
|
|
|
|
## Example
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
2022-09-29 23:03:28 +02:00
|
|
|
const store = new Store()
|
|
|
|
store.set('example', 'Hi there')
|
|
|
|
```
|
|
|
|
|
|
|
|
## Notes
|
|
|
|
|
|
|
|
You can get/set nested keys either through dot-notation, or by passing an
|
|
|
|
array:
|
|
|
|
|
|
|
|
```js
|
|
|
|
const store = new Store()
|
|
|
|
|
|
|
|
store.set('my.nested.example', 'Hi there')
|
|
|
|
store.set(['my', 'other', 'nested', 'example'], 'Oh hi again')
|
|
|
|
|
|
|
|
let value
|
|
|
|
// Dot notation
|
|
|
|
value = store.get('my.nested.example') // works
|
|
|
|
value = store.get('my.other.nested.example') // works
|
|
|
|
// Using an array
|
|
|
|
value = store.get(['my', 'nested', 'example']) // works
|
|
|
|
value = store.get(['my', 'other', 'nested', 'example']) // works
|
|
|
|
// Direct access to the store object
|
|
|
|
value = store.my.nested.example // Also works
|
|
|
|
value = store.my.other.nested.example // Also works
|
2021-08-25 16:09:31 +02:00
|
|
|
```
|