mafortis
mafortis

Reputation: 7128

Vuejs combine array child's as an array

I have such data:

one

Logic

  1. Returned data has sub-data (array) named links
  2. Each link has child named closures
  3. I need to return these closures as of an array at once.

Code

axios.post('/api/valChanger', {[val]: e})
  .then(res => {
    this.closures = res.data.data.links.closures;
  })
  .catch(error => {
    //...
  });

Any idea?

Upvotes: 0

Views: 33

Answers (1)

Ilijanovic
Ilijanovic

Reputation: 14904

Use the rest operator for this case:

axios.post('/api/valChanger', {[val]: e})
  .then(res => {
    let links = res.data.links;
    for(let i = 0; i < links.length; i++){
       this.closures = [...this.closures, ...links[i].closures]
    }

  })
  .catch(error => {
    //...
  });

Upvotes: 1

Related Questions