0

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?

0

1 Answer 1

1

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 => {
    //...
  });
Sign up to request clarification or add additional context in comments.

8 Comments

i get red line error under ..., parts ibb.co/p4GnNzk
only at this.closures...?
shared screenshot
oh sorry what a dumb mistake, the points need to be infront of the variable i edited my answer
yes i already did that but i guess this is the correct one this.closures = [...links[i].closures] i don't need to repeat my closures inside my closures again right?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.