loại bỏ yếu tố đầu tiên từ mảng và trả lại mảng trừ đi các yếu tố đầu tiên
var myarray = ["item 1", "item 2", "item 3", "item 4"];
//removes the first element of the array, and returns that element.
alert(myarray.shift());
//alerts "item 1"
//removes the last element of the array, and returns that element.
alert(myarray.pop());
//alerts "item 4"
- Làm thế nào để loại bỏ các mảng đầu tiên nhưng trả lại mảng trừ đi các yếu tố đầu tiên
- Trong ví dụ của tôi nên nhận được
"item 2", "item 3", "item 4"
khi tôi xóa phần tử đầu tiên
'alert (Array.slice (1)) 'hoặc' array.shift(); alert (mảng); ' – Thomas
@Thomas khi tôi sử dụng' myarray.shift() 'trả' "mục 1" 'những gì tôi muốn là trở' "mục 2", "mục 3", "mục 4" ' –
Vui lòng đọc toàn bộ mã tôi đã viết, sử dụng 'shift()' – Thomas