Skip to content

arrayEmptyCallbackSlots

Reports array methods with callbacks that will never be invoked on arrays with empty slots.

✅ This rule is included in the ts logical and logicalStrict presets.

When the Array constructor is called with a single number argument, it creates an array with the specified number of empty slots (not actual undefined values). Callback methods like map, filter, forEach, and others skip empty slots, so callbacks passed to these methods will never be invoked.

This rule reports when array methods with callbacks are called on arrays created with new Array(n).

72n5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0Arr5<3(sp ansty="le--0:#F78C6C;--1:#AA09">8<25sp ansty="le--0:#D6DEEB;--1:#403F">5<3)sp ansty="le--0:#C792EA;--1:#8844">AB0m5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1(sp ansty="le--0:#D7DBE0;--1:#403F">5<3_sp ansty="le--0:#D9F5DD;--1:#1111">1<1)sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C792EA;--1:#8844">AE<=>sp ansty="le--0:#D6DEEB;--1:#403F">5sp><3 sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>72n5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0Arr5<3(sp ansty="le--0:#F78C6C;--1:#AA09">82<10sp ansty="le--0:#D6DEEB;--1:#403F">5<3)sp ansty="le--0:#C792EA;--1:#8844">AB0filt5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53val1<1)sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C792EA;--1:#8844">AE<=>sp ansty="le--0:#D6DEEB;--1:#403F">53 valusp>Asp ansty="le--0:#D6DEEB;--1:#403F">5sp><3 sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>72n5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0Arr5<3(sp ansty="le--0:#F78C6C;--1:#AA09">8<23sp ansty="le--0:#D6DEEB;--1:#403F">5<3)sp ansty="le--0:#C792EA;--1:#8844">AB0forEa5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53it1<1)sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C792EA;--1:#8844">AE<=>sp ansty="le--0:#D6DEEB;--1:#403F">53 consosp>AB0l53(item)<);d ivclassNa="meco"><);d>72n5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0Arr5<3(sp ansty="le--0:#F78C6C;--1:#AA09">8<25sp ansty="le--0:#D6DEEB;--1:#403F">5<3)sp ansty="le--0:#C792EA;--1:#8844">AB0eve5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53val1<1)sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C792EA;--1:#8844">AE<=>sp ansty="le--0:#D6DEEB;--1:#403F">53 valusp>AE!<==sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0undefin53<);d ivclassNa="meco"><);d>
6E7<2new spans="tyle--0:#D6DEEB;--1:#40">361B0A30<9825 spans="tyle--0:#D6DEEB;--1:#40">34<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B030<9820 spans="tyle--0:#D6DEEB;--1:#40">34<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0map spans="tyle--0:#D6DEEB;--1:#40">31<111( spans="tyle--0:#D7DBE0;--1:#40">31<111) spans="tyle--0:#D6DEEB;--1:#40">344 spans="tyle--0:#D6DEEB;--1:#40">3>0<9821 spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name">< 1)><;di vdivclass="Nameexpressive-">3F53A4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B03F53({ leng0<9825 spans="tyle--0:#D6DEEB;--1:#40">3F53< }, spans="tyle--0:#D9F5DD;--1:#11">1<111( spans="tyle--1:#40"><3F53 spans="tyle--0:#D7">DDEDBE0i1<111) spans="tyle--0:#D6DEEB;--1:#40">344 spans="tyle--0:#D6DEEB;--1:#40">3F53 ind><;di vdivclass="Nameexpressive-">6E7<2new spans="tyle--0:#D6DEEB;--1:#40">361B0A30<9825 spans="tyle--0:#D6DEEB;--1:#40">34<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0361B0undef34<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0for31<111( spans="tyle--0:#D7DBE0;--1:#40">3F531<111) spans="tyle--0:#D6DEEB;--1:#40">344 spans="tyle--0:#D6DEEB;--1:#40">3F53 con>4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0log spans="tyle--0:#D6DEEB;--1:#40">3F53(ite<;di vdivclass="Nameexpressive-">30<9821 spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#F78C6C;--1:#AA">0<9822 spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#F78C6C;--1:#AA">0<9823 spans="tyle--0:#D6DEEB;--1:#40">34<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0map spans="tyle--0:#D6DEEB;--1:#40">31<111( spans="tyle--0:#D7DBE0;--1:#40">3F53v1<111) spans="tyle--0:#D6DEEB;--1:#40">344 spans="tyle--0:#D6DEEB;--1:#40">3F53 va>4<4AE* spans="tyle--0:#D6DEEB;--1:#40">30<9822 spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name">< 2)>

This rule is not configurable.

If you intentionally use new Array(n) for its other properties (like setting length) and understand that callbacks won’t be invoked, you can disable this rule. However, this pattern is rarely intentional and usually indicates a bug.