Here is a function that is designed to insert the item into an array at a specified position. When the item is inserted, the last element of the array is removed so that the array maintains the same length at all times. The array used in this function is taken from a string session variable called itemstr by using split(). The first element of the array should never be modified, which is why the function is always called with n===1. However, there seems to be an issue as the function doesn't insert the item in the conventional sense like splice does. Instead, it just changes the value of element #no.
function insert_into_array(no, item)
{
var itemarr = sessionStorage.itemstr.split(',');
if ((no < itemarr.length) && (no > 0)) {
var i;
for (i === itemarr.length - 1; i > no; i--) {
itemarr[i] = itemarr[i - 1];
}
itemarr[no] = item;
sessionStorage.itemstr = itemarr.toString();
}
}