0

Right now vue inside mounted function calls a napi and gets the value for teambytime2. When it fetch the values using an api it looks like

enter image description here

Below is the axios get url used to fetch the data and pass it on to this.teamByTime2.

axios.get(https://usemyapi90.com/currentDate).then(response => 
      (
        this.teamByTime2 = response.data
      ));

Structure for the fetched data is below

> teamByTime2
  >> 0
    >>> Booker
    >>> Player
    id
    updatedAt
    enter code here

  >> 1
    >>> Booker
    >>> Player
    id
    updatedAt

Any suggestion on how to move object structure for Booker inside the Player ?

> teamByTime2
  >> 0
    >>> Player
     >>>> Booker
    id
    updatedAt
    enter code here

  >> 1
    >>> Player
      >>>> Booker
    id
    updatedAt

1 Answer 1

1

If you have access to the api code you can directly modify the data output, if you don't have access then you could do something like this:

for(let i=0; i < response.data.length; i++){
   let item = data[i]
   item.Booker.Player = item.Player
  
  //if you wanna delete from main object 
   delete item.Player
  
  //push in the array
   this.teamByTime2.push(item)
}

Sign up to request clarification or add additional context in comments.

Comments

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.