1

I have an array plan defined using store state management as follows:

import { reactive } from 'vue'

export const store = reactive({
    plan: []
})

I want to reset this array before filling it again, I have tried:

import { store } from "./store.js";
store.plan = [];
store.plan = newPlan; // store.plan is accumulated here without reset!

Can you please tell me how can I reset this reactive array before assigning the new array to it?

Elikill58
  • 4,050
  • 24
  • 23
  • 45
Bilal
  • 3,191
  • 4
  • 21
  • 49

1 Answers1

0

Actually, you are creating a new instance for the array. As the objective of reactive function is to share the same instance, it keeps the old array.

You should edit the array instance by cleaning it like that:

store.plan.splice(0, store.plan.length)

You can also use store.plan.length = 0.

Elikill58
  • 4,050
  • 24
  • 23
  • 45