Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
How to modify object value stored in a literal through this context in Vue or JavaScript?

I am in Vue.js and trying to correct inappropriate quantity input value like "12jd". They belong to item objects which are in a array literal called store (which is defined in data( ) return). The problematic code is in the input event handler function which gets the item's index - idx in which the bad quantity was written.

Everything goes well until I try to assign the proper array, with no bad quantity, to the original store in the this context. This part does not work, no value gets changed in the original.

failed(idx) {

  const storeCopy = lodash.cloneDeep(this.store); //deep copy the store literal

  const unmodified = storeCopy.filter((item) => item.id !== idx);

  const modified = storeCopy.filter((item) => item.id === idx)[0]; //slice out the relevant part
  const modifiedCopy = JSON.parse(JSON.stringify(modified)); //deep copy the item object

  const input = parseInt((" " + modifiedCopy.quantity).slice(1)); //get parsed input from deep copied string

  const store = [
    Object.defineProperty(modifiedCopy, "quantity", {
      value: isNaN(input) ? 0 : input,
    }),
    ...unmodified,
  ]; //correct the input and put it back to the array
  console.log(store);

  this.store.length = 0; //from this it's messed up
  this.store = store;
}

I do deep copy even three times, still the problem backpropagates to console logged array after uncommenting the last two lines. Without them it's fine.

Why does the reference not get garbage collected, after setting this.store.length to 0, or this.store to [] at all? What do I miss out, is there any original reference left in the new array maybe? Any help appreciated! Thanks

Edited

Here's the output without then with the two last line:

Without the last two lines

I don't even understand who it's possible that store in the local scope is affected backwards, by inserting those two lines. Anyways It gets restored somehow to the bad value "12jd".

With the two lines

Even the log looks different, I have to click on the three dots to reveal the values.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!