I know this is a basic question, I have limited knowledge in JS. Is there an alternative method to keep an array length fixed with queue feature. The array keep receiving data I want always to remove the first element of the array?
var a=Math.random;
var array=[];
if (array.length < 4) {
array.push(a);
} else {
array.shift();
}
console.log("array",array);
I was hoping if there is such thing as following:
var a=Math.random;
var array=[];
array.length=4
array.push(a);
console.log(array);