Test name | Executions per second |
---|---|
Delete by Splice | 1569919.9 Ops/sec |
Delete by Splice Index | 1629117.5 Ops/sec |
Delete by Filter | 1718607.2 Ops/sec |
<script>
var array = ["m1c6kzws0iubt8g0zlsug14i","xalskr21dm5ke5wczew154s4i","hvbfe3uq3pmoehpilh4zpvi","ffr2btp9rihf3qce770ttke29","ymwh11qu16qwqn5vaafxhia4i","1l7rj49636ddmk3cbszitchaor","bg1njla9dvdkdlw9mbz1l9pb9","201y3ambt118dt7j7bxc6ry66r","hsgzqv2ex2j9j8znv3uzbyb9","k8tuq5ucdx1whgkdcby44pldi","2sjycnx525scxzfxfmwl7q4cxr"];
</script>
/* these functions assume that only one element matches, so they do not loop! */
function deleteBySplice (array, element) {
array.splice( array.indexOf( element ), 1 );
}
function deleteBySpliceIdx (array, element) {
array.splice( element, 1 );
}
function deleteByFilter (array, element) {
array = array.filter( el => el !== element );
}
deleteBySplice( array, "2sjycnx525scxzfxfmwl7q4cxr" );
deleteBySplice( array, "m1c6kzws0iubt8g0zlsug14i" );
deleteBySplice( array, "1l7rj49636ddmk3cbszitchaor" );
deleteBySpliceIdx( array, 10 );
deleteBySpliceIdx( array, 0 );
deleteBySpliceIdx( array, 5 );
deleteByFilter( array, "2sjycnx525scxzfxfmwl7q4cxr" );
deleteByFilter( array, "m1c6kzws0iubt8g0zlsug14i" );
deleteByFilter( array, "1l7rj49636ddmk3cbszitchaor" );