The magic slice method

Friends who are beginners in js must know that the slice method of the array does not change the original array. I have always believed in it for so many years. But when I was working on a project recently, I suddenly discovered a magical thing: it can change the original array (object array)!

1. The logic needs to change every 10 audit information from unapproved to audited in batches at regular intervals:

   ==>    

 2. My code is written like this: (the timer is omitted)

 As a result, both the changeData and the ddd original array printed out in this way have changed. .

3. Summary: In fact, it is still a problem of shallow copy and deep copy. Although the intercepted part is assigned to a new variable, it still points to the same address. It seems that we must pay attention to it when operating object arrays in the future.

Guess you like

Origin blog.csdn.net/BUG_CONQUEROR_LI/article/details/129124063