Why after assigning the variable becomes a reference to the object?

I write vue.js + laravel app.
My method of retrieving and processing data

getTestimonials() {
axios.get('/api/testimonials?page='+this.pagination.current_page)
 .then(res => {

 var response = res.data;
 this.testimonials = response;
console.log(Res. data.data);
console.log(response.data);
console.log(this.testimonials.data);
 this.testimonials.data = [];
console.log(Res. data.data);
console.log(response.data);
console.log(this.testimonials.data);

 ... in the next code i want to use res.data.data but one is emprty

})
 .catch((error) => console.log(error));
 },

In the console I see this
5a7342e369069709237265.png
Can I reset an array of testimonials.data and use res.data.data next? If I can, how and why like this to happen when you assign?
Thanks in advance!!
June 8th 19 at 16:58
1 answer
June 8th 19 at 17:00
Solution
Can I reset an array of testimonials.data and use res.data.data next?

this.testimonials.data = [];

Well, already. Or you are confused by the presence of the array __ob__?
Or are you embarrassed that arrays in JS are passed by reference? So copy it by the slice.
No, bothers me that the array res.data.data is also empty! I want to use it on... - cesar65 commented on June 8th 19 at 17:03
you said that you changed it from the link. Maybe you should learn C and pointers? - cortney.Kuhic commented on June 8th 19 at 17:06
I you even the name of the method is written. Really too lazy to try?
console.clear()

const data = {
 data: ['w', 't', 'f']
}
let copy = data
const slice = data.data.slice()

console.log(data.data, copy.data, slice)
copy.data = []

console.log(data.data, copy.data, slice)
- Kameron_Hilpert34 commented on June 8th 19 at 17:09
Thanks for the reply, I did not know that the array is passed.
Now use slice - cesar65 commented on June 8th 19 at 17:12

Find more questions by tags Vue.js