[Vuejs]-How to modify object stored in local storage in javascript?

3👍

If all you want is to modify and put back…

Code:

    let data = JSON.parse(this.$localStorage.get(`work_order_${this.id}`));

    data.initial_kg = "Your value here";
    data.final_kg = "Your value here";

    this.$localStorage.set(`work_order_${this.id}`, JSON.stringify(data));

    // But maybe you could (Vanilla)

    let data = JSON.parse(localStorage.getItem(`work_order_${this.id}`));

    data.initial_kg = "Your value here";
    data.final_kg = "Your value here";

    localStorage.setItem(`work_order_${this.id}`, JSON.stringify(data));

    // Also, JSON parse and stringify aren't async methods, use them without await.

Hope this is what you wanted.

Leave a comment