Search code examples
arraystypescriptaxiosinfinite-scrollvue3-carousel

Push an array to an array of the same type in Vue3 typescript


I have an array of Obj1. In a project vue 3+ts , after clicking the button "load more", i call via axios the backend service and retrive an array of the same type. I want to append this rows to the previous array, but it is not working :

this.Array1.push(response.data)

If i add 1 item at the time, the Array1 gets updated:

this.Array1.push(response.data[0])

What am i missing?


Solution

  • Based on your question that this code works:

    this.Array1.push(response.data.results[0])
    

    Indicates that response.data.results is the array you want to work with. If you want to push that entire array in, you can simply use the ES6 spread operator:

    this.Array1.push(...response.data.results)