Which approach to delete the first element of an array in js provides better performance?
Assume we have this array:
let fruits = ['Apple', 'Orange', 'Banana', 'Lemon'];
1. shift approach
let a = fruits.shift();
2. splice approach
let [b] = fruits.splice(0, 1);
3. slice approach
let c;
[c, fruits] = [...fruits.slice(0, 1), fruits.slice(1)]
4. Destructuring approach
let d;
[d, ...fruits] = fruits;
Please mention the reasons why one one these approaches is faster than another.
I did some tests in jsbench.me & perf.link but I ran the exact same tests multiple times and everytime I got 180 degrees opposite results.
I know this things are different from one environment and engine to another so I want to know which one is better in Chrome V8 engine.