I am generating an array like :
const myArray = Array.from({length: 5}, (e, i) => emptyX)
myArray starts with 5 elements of emptyX.
Is there a simple way/method which unshift the array without changing its size ? Whenever I call it I must find the initial size.
exemple:
myArray.unshift(X1) => [X1, emptyX, emptyX, emptyX, emptyX]
myArray.unshift(X2) => [X2, X1, emptyX, emptyX, emptyX]
myArray.unshift(X3) => [X3, X2, X1, emptyX, emptyX]
// OR with multiple parameters
myArray.unshift(X4, X5) => [X5, X4, X3, X2, X1]
UPDATE:
Now I am doing :
myArray.unshift(X);
myArray.splice(-1, 1);// or pop()
But it's not what I want, I need just to replace the items because the array size change when I call unshift and splice
.unshift()an element from the array without changing the array size O.o?myArray[0]etc? Like,myArray[0] = X1;?emptyX? Is itnull?undefined? What is supposed to happen when we unshiftX2to[empty, X1]?