let view = [1,2,3,4,5], pageid = '3', index; pageid = Number(pageid); index = view.findIndex(i => i === pageid); if(index !== -1) { view.splice(index, 1); view.push(pageid); }; alert(JSON.stringify(view));