按鍵序列檢測
splice( 從要刪除的索引位置開始 , 刪除的元素數量 ,要插入的元素)
var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
var removed = myFish.splice(2, 0, 'drum');
// 從第二個索引 刪除0個 並且加入"drum"
// myFish 為 ["angel", "clown", "drum", "mandarin", "sturgeon"]
const pressed =[];
const secretCode = 'wesbos'
window.addEventListener('keyup',(e)=>{
pressed.push (e.key);
pressed.splice( -secretCode.length - 1 , pressed.length -secretCode.length );
if(pressed.join('').includes(secretCode)){
console.log('Ding! Ding!')
}
})