Move array element to the first position
function update(e) {

    // find index
    var i = arr.findIndex(o =&gt; o.v === e.v);

    // if already at start, nothing to do
    if (i === 0) return;

    // remove old occurrency, if existing
    if (i &gt; 0) {
        arr.splice( i, 1 );
    }

    // add e to the start
    arr.unshift( e );

    // keep array at the correct size
    arr.length = Math.min( arr.length, 4 );
}


Somewhat less code. I don't know about the performance.