Reports using the delete operator on array values.
✅ This rule is included in the ts logical and logicalStrict presets.
When using the delete operator with an array value, the array’s length property is not affected, but the element at the specified index is removed and leaves an empty slot in the array.
This creates a sparse array, which can lead to unexpected behavior when iterating or checking array properties.
The recommended way to remove an element from an array is by using the Array#splice() method, which properly updates the array’s length and shifts remaining elements.
AEdeclare consB0arr7<2:sp ansty="le--0:#C792EA;--1:#8844">A2:sp>B0numb53[<];d ivclassNa="meec-li">72dele53 arra8<20sp ansty="le--0:#D6DEEB;--1:#403F">5320sp>];d><];d ivclassNa="meco"><];d>];d>];d>AEconsB0iteAE< =sp ansty="le--0:#D6DEEB;--1:#403F">53 =sp>< [sp ansty="le--0:#F78C6C;--1:#AA09">8 [sp><21sp ansty="le--0:#D6DEEB;--1:#403F">5321sp><, sp ansty="le--0:#F78C6C;--1:#AA09">8, sp><22sp ansty="le--0:#D6DEEB;--1:#403F">5322sp><, sp ansty="le--0:#F78C6C;--1:#AA09">8, sp><23sp ansty="le--0:#D6DEEB;--1:#403F">5323sp><];d ivclassNa="meec-li">72dele53 item8<21sp ansty="le--0:#D6DEEB;--1:#403F">5321sp>];d><];d ivclassNa="meco"><];d>];d>];d>AEdeclare consB0matr7<2:sp ansty="le--0:#C792EA;--1:#8844">A2:sp>B0numb53[][<];d ivclassNa="meec-li">72dele53 matri8<20sp ansty="le--0:#D6DEEB;--1:#403F">5320sp><][sp ansty="le--0:#F78C6C;--1:#AA09">8][sp><21sp ansty="le--0:#D6DEEB;--1:#403F">5321sp>];d><];d ivclassNa="meco"><];d>];d>];d> 44AEdeclare co61B0a64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu4AE >3F5<3[] ;divclass="Nameec-">3F53a4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0sp4AE.>30<9820 spans="tyle--0:#D6DEEB;--1:#40">3F9820><53, spans="tyle--0:#F78C6C;--1:#AA">053, ><9821 spans="tyle--0:#D6DEEB;--1:#40">3F9821>3[]><53) ;divclass="Name">< 1)> 1)>53)><;di vdivclass="Nameexpressive-">44AEco61B0i443F<53 [ spans="tyle--0:#F78C6C;--1:#AA">053 [><9821 spans="tyle--0:#D6DEEB;--1:#40">3F9821><53, spans="tyle--0:#F78C6C;--1:#AA">053, ><9822 spans="tyle--0:#D6DEEB;--1:#40">3F9822><53, spans="tyle--0:#F78C6C;--1:#AA">053, ><9823 spans="tyle--0:#D6DEEB;--1:#40">3F9823><53] ;divclass="Nameec-">3F53i4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0sp4AE.>30<9821 spans="tyle--0:#D6DEEB;--1:#40">3F9821><53, spans="tyle--0:#F78C6C;--1:#AA">053, ><9821 spans="tyle--0:#D6DEEB;--1:#40">3F9821>53]><53) ;divclass="Name">< 1)> 1)>53)>;di><;di vdivclass="Nameexpressive-">44AEdeclare co61B<0obj spans="tyle--0:#7FDBCA;--1:#09">60obj>44A<3F53 spans="tyle--0:#D6">D3F53>DBE<0key spans="tyle--0:#7FDBCA;--1:#09">60key>4<4AE spans="tyle--0:#C5E478;--1:#3B">61B0st4AE >364<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu4AE >4436E72de3F53 1<111" spans="tyle--0:#ECC48D;--1:#98">4E4111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53] ;divclass="Name">53]>;di><;di vdivclass="Nameexpressive-">44AEdeclare co61B<0map spans="tyle--0:#7FDBCA;--1:#09">60map>4<4AE spans="tyle--0:#FFCB8B;--1:#11">1114AE ><1Map spans="tyle--0:#C792EA;--1:#88">41Map><4AE< spans="tyle--0:#C5E478;--1:#3B">61B0st4AE<>4461B0nu4<4AE> spans="tyle--0:#D6DEEB;--1:#40">34AE>>3F5<3map spans="tyle--0:#C792EA;--1:#88">43map><4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0de4AE.>31<111" spans="tyle--0:#ECC48D;--1:#98">4E4111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53) ;divclass="Name">;map.delete("ke">53)>;di>
This rule is not configurable.
If you intentionally want to create sparse arrays with empty slots, you can disable this rule.
Some codebases may use sparse arrays for specific algorithms or memory optimization purposes.