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

113
Views
Vue 3: Flattening a reactive array of objects without destroying reactivity

When I try to flatten a Vue 3 reactive array of nested objects, I lose their reactivity and my app literally crashes and hangs the browser window.

My Vue 3 component defines an array as a list of objects:

this.grouped = [
          [this.tokens[0]],
          [this.tokens[1]],
          [this.tokens[2],this.tokens[3],this.tokens[4]], // nested
          [this.tokens[5]]
]

I need to take the the 2nd index (where the array nests 3 objects) and flatten it so that the resulting array looks like it would have been defined like this:

this.grouped = [
          [this.tokens[0]],
          [this.tokens[1]],
          [this.tokens[2]], //flattened
          [this.tokens[3]], //flattened
          [this.tokens[4]], //flattened
          [this.tokens[5]]
]

When I try to use splice to do this, the reactivity is lost (example below, showing the lost reactivity. Any ideas how to do it?

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try Array#flat:

const res = this.grouped.flat();
about 4 years ago · Juan Pablo Isaza Report
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!