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

86
Views
Array does not loose reference
 async create() {
      let formData = new FormData()
      formData.append('name', this.name)
      formData.append('size', JSON.stringify(this.size))
      let copy = [...this.layers] // <==== HERE I TRY TO COPY 
      copy.forEach((layer, layerIndex) => {
        layer.traits.forEach((trait, traitIndex) => {
          if (!(trait.file instanceof Blob)) return
          let name = `file_${layerIndex}_${traitIndex}`
          formData.append(`images`, trait.file, name)
          trait.file = name
        })
      })
      formData.append('layers', JSON.stringify(copy))
      try {
        let result = await this.$axios.$post('/api/createcollection', formData)
        this.$router.push('/dashboard')
      } catch (err) {
        this.layers = [...copy] // <==== HERE I RESET IT IF ITS FAIL
        this.message = err.response.data
        setTimeout(() => {
          this.message = ''
        }, 5000)
      }
    },

I am not able to set this.layers to the way it was before. I have sent it, but for some reason, copy is the same value as this.layers

Why this is copying the same as this.layers even if I spread it into a new array?

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!