JSFiddle - React, Tailwind, and code Playground
CSS
* { font-family: monospace; }
JavaScript
Array.prototype.insert1 = function(index) {
this.splice.apply(this, [index, 0].concat(
Array.prototype.slice.call(arguments, 1)));
return this;
};
Array.prototype.insert2 = function(index) {
index = Math.min(index, this.length);
arguments.length > 1
&& this.splice.apply(this, [index, 0].concat([].pop.call(arguments)))
&& this.insert2.apply(this, arguments);
return this;
};
document.body.innerHTML =
'<p>Input: ["a", "b", "c", "d"]</p>' +
'<p>Insert arguments ("V", ["W", "X", "Y"], "Z") at index 2</p>' +
'<p><b>Insert 1:</b><br />' +
["a", "b", "c", "d"].insert1(2, "V", ["W", "X", "Y"], "Z").join(" | ") + '</p>' +
'<p><b>Insert 2:</b><br />' +
["a", "b", "c", "d"].insert2(2, "V", ["W", "X", "Y"], "Z").join(" | ") + '</p>';