Test name | Executions per second |
---|---|
Array.prototype.toSpliced | 18843596.0 Ops/sec |
Array.prototype.slice + Array.prototype.unshift | 15991052.0 Ops/sec |
Spread operator | 20711536.0 Ops/sec |
var array = ["hello", true, 7];
var newElement = "new";
const newArray = array.toSpliced(0, 0, newElement);
const newArray = array.slice();
newArray.unshift(newElement);
const newArray = [newElement, array];