const arr = [1, 2, 3, 4, 5, 6] // 將元素添加到數組末尾 arr.push(7) // arr: [1, 2, 3, 4, 5, 6, 7] // 取出數組末尾元素並返回 const pop_res = arr.pop() // arr: [1, 2, 3, 4, 5, 6], pop_res: 7 // 總結:push、pop方法名稱和棧的進棧、出棧操作名稱相同,這樣很方便記憶 // 將元素添加到數組開頭 arr.unshift(0) // arr: [0, 1, 2, 3, 4, 5, 6] // 取出數組開頭元素並返回 const sft_res = arr.shift() // arr: [1, 2, 3, 4, 5, 6], sft_res = 0 // 總計:unshift、shift方法名稱就不是那么友好了(英語差.jpg), // 於是我查了一下單詞的含義,用“出售”記憶shift含義就很清晰了!