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; } 
  • one
    Recommendations about deletion relate to the use of the delete operator, because it leaves undefined instead of the element in its place - Alexey Shimansky
  • the best way to create a new array without unnecessary elements - Grundy
  • If elements are removed from the end, then pop or reduce the length . - Arnial pm
  • Yes, but what is the answer to my question? Removal from the middle, the fastest way. - R. Matveev

0