Here we write fast and economical JavaScript code written:
Array Tips
Do not remove items. If empty spaces are formed in the array, V8 switches to the dictionary method of working with arrays, which makes the script even slower.
In the code below, I delete the 3rd element. Is the splice command just throwing an element out of an array (and this applies to an article from the habr), or does it re-form the array after removing the element, and there are no empty places?
In terms of speed, what is the best way to remove an element from an array by its index (up to tens of milliseconds of interest)?
function a(){ var b = []; for (var i = 0; i < 5; i++){ b[i] = i; } b.splice(2, 1); return; }
deleteoperator, because it leavesundefinedinstead of the element in its place - Alexey Shimanskypopor reduce thelength. - Arnial pm