D
D
DragonChris2018-02-01 19:41:19
Vue.js
DragonChris, 2018-02-01 19:41:19

Why does a variable become a reference to an object after being assigned?

I am writing a vue.js + laravel application.
My method of receiving 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 the testimonials.data array and use res.data.data further? If I can then how and why does this happen when assigned?
Thanks in advance!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2018-02-01
@DragonChris

Can I zero out the testimonials.data array and use res.data.data further?

Well, already. Or are you confused by the presence of __ob__ in the array ?
Or does it confuse you that arrays in JS are passed by reference? So copy it with the slice method .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question