> For the complete documentation index, see [llms.txt](https://132oq-szjxckld--diwejk1k2j-1123n.gitbook.io/documentation-studio-shento/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://132oq-szjxckld--diwejk1k2j-1123n.gitbook.io/documentation-studio-shento/getting-started-with-sveltekit/closer-look-at-reactivity/updating-arrays-and-objects.md).

# Updating Arrays & Objects

If you want to manipulate arrays. You must first declare that it's reactive using `$state(value)`

## Adding an item to an array

```html
<script>
  let sample = $state(['apple', 'peas']);
  sample.push('banana');
</script>
```

## Adding an item to the begin of an array

```html
<script>
  let sample = $state(['apple', 'peas']);
  sample.unshift('banana');
</script>
```

## Deleting an item based on the name&#x20;

```html
<script>
  let list = $state(['apple', 'peas', 'bananas']);
  let filteredList = list.filter((item) => item !== 'apple');
</script>
```

## Filtering an item based on the name

```html
<script>
  let list = $state(['apple', 'peas', 'bananas']);
  let filteredList = list.filter((item) => item === 'apple');
</script>
```

## Deleting first item in an array

```html
<script>
  let sample = $state(['apple', 'peas']);
  let UpdatedSample = sample.slice(1);
</script>
```

## Deleting last item in an array

```html
<script>
  let sample = $state(['apple', 'peas']);
  let UpdatedSample = sample.slice(0, -1);
</script>
```
