I assume that your application scenario is to automatically detect the length when pushing elements into the array, and delete them after copying 9. Wouldn’t it be very rigid to call the detection method every time you push? I have an idea: rewrite the push method of array
Set arr.length=9 directly; no need to judge!
Use arr.length to judge
if(arr.length > 9){
}
This ensures that the maximum length is 9
I assume that your application scenario is to automatically detect the length when pushing elements into the array, and delete them after copying 9. Wouldn’t it be very rigid to call the detection method every time you push? I have an idea: rewrite the push method of array
arr.length=9;