Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
Description
Description
Deleting an array element can lead to unexpected (for some) behaviour since it leaves 'length' unchanged. Some might say that using delete on array elements should best be avoided and there are alternatives - splice() seems to be preferred.
Having a rule to prevent delete being used on arrays would be beneficial.
Fail
>varmyArray=[1,2,3];undefined>deletemyArray[1];true>myArray(3) [1,empty,3]>myArray[1]undefined>myArray.length3
Pass
>varmyArray=[1,2,3];(3) [1,2,3]>myArray.splice(1,1)[2]>myArray(2) [1,3]