Hộp thoại phụ INPUT ARRAY xử lý phiên bản danh sách bản ghi. Bộ điều khiển này cho phép người dùng chỉnh sửa trực tiếp các hàng hiện có và tạo hoặc xóa các hàng bằng các hành động ngầm định
Các hàng có thể được tạo bằng hành động nối thêm hoặc chèn và có thể được xóa bằng hành động xóa. Ba hành động ngầm định này được tạo tự động bởi hộp thoại
- Hành động chèn tạo một hàng mới trước hàng hiện tại. Nếu không có hàng nào trong danh sách, hãy chèn thêm một hàng mới
- Hành động chắp thêm tạo một hàng mới sau hàng cuối cùng của danh sách
- Thao tác xóa sẽ xóa hàng hiện tại
Để ngăn INPUT ARRAY tạo ra các hành động ẩn này, hãy đặt các thuộc tính kiểm soát APPEND ROW, INSERT ROW và/hoặc DELETE ROW thành FALSE. Để từ chối hoàn toàn việc thêm hàng, cũng đặt thuộc tính AUTO APPEND thành FALSE.
DIALOG ATTRIBUTES[UNBUFFERED] INPUT ARRAY p_items FROM sa.* ATTRIBUTES[AUTO APPEND=FALSE, INSERT ROW=FALSE] ... END INPUT END DIALOG
Các khối điều khiển cụ thể có sẵn để kiểm soát khi một hàng được tạo hoặc xóa
- Các khối điều khiển TRƯỚC CHÈN và SAU KHI CHÈN có thể được sử dụng để điều khiển việc tạo hàng. Hủy tạo hàng bằng CANCEL INSERT trong khối TRƯỚC CHÈN hoặc SAU KHI CHÈN
- Các khối điều khiển TRƯỚC KHI XÓA và SAU KHI XÓA có thể được sử dụng để điều khiển việc xóa hàng. Hủy xóa hàng bằng lệnh CANCEL DELETE trong TRƯỚC KHI XÓA
Mảng động và giao diện người dùng. Lớp hộp thoại cung cấp các phương thức như mảng. xóaElement[] hoặc ui. hộp thoại. appendRow[] để sửa đổi danh sách. Khi sử dụng các phương thức này, các trình kích hoạt được xác định trước như TRƯỚC KHI XÓA hoặc TRƯỚC KHI CHÈN không được thực thi. Mặc dù việc sử dụng các phương pháp này trong Mảng HIỂN THỊ là an toàn, nhưng bạn phải cẩn thận khi sử dụng Mảng ĐẦU VÀO. Ví dụ: bạn không nên gọi các phương thức như vậy trong trình kích hoạt như TRƯỚC HÀNG, SAU KHI CHÈN, TRƯỚC KHI XÓA
Người dùng có thể nối thêm các hàng tạm thời bằng cách di chuyển đến cuối danh sách hoặc khi thực hiện hành động nối thêm. Việc thêm các hàng tạm thời khác với việc thực hiện hành động chèn;
Theo mặc định, khi hàng cuối cùng bị xóa bởi thao tác xóa, lệnh INPUT ARRAY sẽ tự động tạo một hàng tạm thời mới ở cùng vị trí. Hiệu ứng hình ảnh của hành vi này có thể bị hiểu sai - nếu không có dữ liệu nào được nhập vào hàng cuối cùng, bạn sẽ không thấy bất kỳ sự khác biệt nào. Tuy nhiên, hàng cuối cùng thực sự bị xóa và một hàng mới được tạo, và chuỗi khối điều khiển TRƯỚC XÓA / SAU KHI XÓA / SAU ROW / TRƯỚC ROW / TRƯỚC CHÈN được thực thi. Để từ chối để tránh việc tạo một hàng tạm thời mới khi hàng cuối cùng bị xóa, hãy đặt thuộc tính AUTO APPEND = FALSE
Các hành động chèn, nối thêm hoặc xóa có thể tự động bị vô hiệu hóa tùy theo ngữ cảnh. Nếu INPUT ARRAY đang sử dụng một mảng tĩnh đã đầy hoặc nếu đã đạt đến thuộc tính MAXCOUNT, thì cả thao tác chèn và nối thêm sẽ bị vô hiệu hóa. Hành động xóa tự động bị tắt khi AUTO APPEND = FALSE và không còn hàng nào trong mảng
Mảng JavaScript là một biến duy nhất được sử dụng để lưu trữ các phần tử hoặc một nhóm giá trị. Bạn có thể thêm bớt các phần tử trong mảng ở bất kỳ vị trí nào. Trong bài viết này, chúng ta sẽ thảo luận về các cách khác nhau để loại bỏ các phần tử khỏi mảng.
Có nhiều phương pháp được sử dụng để xóa các phần tử khỏi mảng JavaScript sẽ được thảo luận bên dưới.
- hàm pop[]. Phương thức này dùng để loại bỏ các phần tử ở cuối mảng
- hàm shift[]. Phương thức này được sử dụng để loại bỏ các phần tử từ đầu của một mảng
- chức năng mối nối []. Phương pháp này được sử dụng để xóa các phần tử khỏi chỉ mục cụ thể của một mảng
- chức năng bộ lọc[]. Phương pháp này được sử dụng để loại bỏ các phần tử theo cách lập trình
Ghi chú. Có một số phương thức khác được tạo bởi các phương thức sẵn có của JavaScript
Các ví dụ dưới đây minh họa các phương pháp xóa phần tử khỏi mảng JavaScript
Loại bỏ các phần tử Array bằng cách sử dụng phương thức pop[]. Phương thức này dùng để xóa phần tử cuối cùng của mảng và trả về phần tử đã xóa. Hàm này giảm độ dài của mảng xuống 1.
ví dụ 1.
jav
Original array: pop, splice, filter, shift Array Length: 03
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 05
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 07
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop0
Removed element: shift Remaining elements: splice, filter, pop1
Removed element: shift Remaining elements: splice, filter, pop2
Removed element: shift Remaining elements: splice, filter, pop3
Removed element: shift Remaining elements: splice, filter, pop4
Removed element: shift Remaining elements: splice, filter, pop5
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop7
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop9
Removed element: shift Remaining elements: splice, filter, pop6
Original array: pop, splice, filter, shift Array Length: 091
Original array: pop, splice, filter, shift Array Length: 092
Original array: pop, splice, filter, shift Array Length: 08
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 095
Removed element: shift Remaining elements: splice, filter, pop2
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 098
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 091
Original array: pop, splice, filter, shift Array Length: 092
Original array: pop, splice, filter, shift Array Length: 093
Original array: pop, splice, filter, shift Array Length: 094
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 090____197
Original array: pop, splice, filter, shift Array Length: 098
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 080
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 082
Original array: pop, splice, filter, shift Array Length: 083
đầu ra.
Original array: pop, splice, filter, shift Array Length: 02
ví dụ 2.
jav
Original array: pop, splice, filter, shift Array Length: 03
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 086
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 089
Original array: pop, splice, filter, shift Array Length: 091
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop7
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop9
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop5
Original array: pop, splice, filter, shift Array Length: 067
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 001
Original array: pop, splice, filter, shift Array Length: 002
Original array: pop, splice, filter, shift Array Length: 093
Original array: pop, splice, filter, shift Array Length: 004
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 007
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 009
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 08
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 093
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 095
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 097
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 091
Original array: pop, splice, filter, shift Array Length: 092
đầu ra.
Original array: pop, splice, filter, shift Array Length: 0
Loại bỏ các phần tử Array bằng cách sử dụng phương thức shift[]. Phương thức này dùng để loại bỏ phần tử đầu tiên của mảng và giảm kích thước của mảng ban đầu đi 1.
Thí dụ.
jav
Original array: pop, splice, filter, shift Array Length: 03
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 095
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 097
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop0
Removed element: shift Remaining elements: splice, filter, pop1
Removed element: shift Remaining elements: splice, filter, pop2
Removed element: shift Remaining elements: splice, filter, pop3
Removed element: shift Remaining elements: splice, filter, pop4
Removed element: shift Remaining elements: splice, filter, pop5
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop7
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop9
Removed element: shift Remaining elements: splice, filter, pop6
Original array: pop, splice, filter, shift Array Length: 091
Original array: pop, splice, filter, shift Array Length: 092
Original array: pop, splice, filter, shift Array Length: 08
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 014
Removed element: shift Remaining elements: splice, filter, pop2
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 017
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 091
Original array: pop, splice, filter, shift Array Length: 021
Original array: pop, splice, filter, shift Array Length: 093
Original array: pop, splice, filter, shift Array Length: 094
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 090____197
Original array: pop, splice, filter, shift Array Length: 098
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 080
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 082
Original array: pop, splice, filter, shift Array Length: 032
đầu ra.
________số 8Loại bỏ các phần tử Array bằng phương thức splice[]. Phương thức này được sử dụng để sửa đổi nội dung của một mảng bằng cách loại bỏ các phần tử hiện có và/hoặc bằng cách thêm các phần tử mới. Để xóa các phần tử bằng phương thức mối nối[], bạn có thể chỉ định các phần tử theo nhiều cách khác nhau.
ví dụ 1. Sử dụng lập chỉ mục của phương thức mối nối để xóa các phần tử khỏi mảng JavaScript.
jav
Original array: pop, splice, filter, shift Array Length: 03
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 035
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop0
Removed element: shift Remaining elements: splice, filter, pop1
Removed element: shift Remaining elements: splice, filter, pop2
Removed element: shift Remaining elements: splice, filter, pop3
Removed element: shift Remaining elements: splice, filter, pop4
Removed element: shift Remaining elements: splice, filter, pop5
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop7
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop9
Removed element: shift Remaining elements: splice, filter, pop6
Original array: pop, splice, filter, shift Array Length: 091
Original array: pop, splice, filter, shift Array Length: 092
Original array: pop, splice, filter, shift Array Length: 08
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 053
Removed element: shift Remaining elements: splice, filter, pop2
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 056
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 090____191
Original array: pop, splice, filter, shift Array Length: 060
Original array: pop, splice, filter, shift Array Length: 093
Original array: pop, splice, filter, shift Array Length: 094
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 090____197
Original array: pop, splice, filter, shift Array Length: 098
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 080
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 082
Original array: pop, splice, filter, shift Array Length: 032
đầu ra.
Original array: pop, splice, filter, shift Array Length: 09
ví dụ 2. Sử dụng giá trị của phương thức mối nối để xóa các phần tử khỏi mảng JavaScript.
jav
Original array: pop, splice, filter, shift Array Length: 072
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 035
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop0
Original array: pop, splice, filter, shift Array Length: 077
Removed element: shift Remaining elements: splice, filter, pop2
Removed element: shift Remaining elements: splice, filter, pop3
Removed element: shift Remaining elements: splice, filter, pop4
Removed element: shift Remaining elements: splice, filter, pop5
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop7
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop9
Removed element: shift Remaining elements: splice, filter, pop6
Original array: pop, splice, filter, shift Array Length: 091
Original array: pop, splice, filter, shift Array Length: 088
Original array: pop, splice, filter, shift Array Length: 08
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 091
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 093
Original array: pop, splice, filter, shift Array Length: 094
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 096
Original array: pop, splice, filter, shift Array Length: 097
Original array: pop, splice, filter, shift Array Length: 098
Original array: pop, splice, filter, shift Array Length: 099
Removed element: shift Remaining elements: splice, filter, pop7
Removed element: shift Remaining elements: splice, filter, pop01
Removed element: shift Remaining elements: splice, filter, pop02
Removed element: shift Remaining elements: splice, filter, pop3
Removed element: shift Remaining elements: splice, filter, pop04
Removed element: shift Remaining elements: splice, filter, pop02
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 091
Original array: pop, splice, filter, shift Array Length: 060
Original array: pop, splice, filter, shift Array Length: 093
Removed element: shift Remaining elements: splice, filter, pop10
Removed element: shift Remaining elements: splice, filter, pop02
Original array: pop, splice, filter, shift Array Length: 090____197
Removed element: shift Remaining elements: splice, filter, pop14
Original array: pop, splice, filter, shift Array Length: 097____697
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 097
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 097
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 082
Removed element: shift Remaining elements: splice, filter, pop23
đầu ra.
Original array: pop, splice, filter, shift Array Length: 09
ví dụ 3. Sử dụng phương thức mối nối để xóa từng phần tử khỏi mảng JavaScript.
jav
Original array: pop, splice, filter, shift Array Length: 03
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop26
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 089
Original array: pop, splice, filter, shift Array Length: 091
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop7
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop9
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop5
Original array: pop, splice, filter, shift Array Length: 067
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 001
Original array: pop, splice, filter, shift Array Length: 002
Original array: pop, splice, filter, shift Array Length: 093
Original array: pop, splice, filter, shift Array Length: 004
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop47
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop49
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 090
Removed element: shift Remaining elements: splice, filter, pop52
Removed element: shift Remaining elements: splice, filter, pop53
Original array: pop, splice, filter, shift Array Length: 092
đầu ra.
Original array: pop, splice, filter, shift Array Length: 08
Loại bỏ các phần tử Array bằng cách sử dụng phương thức filter[]. Phương thức này được sử dụng để tạo một mảng mới từ một mảng đã cho chỉ bao gồm các phần tử từ mảng đã cho thỏa mãn một điều kiện được đặt bởi hàm đối số. Để xóa các phần tử bằng phương thức filter[], bạn có thể chỉ định các phần tử theo nhiều cách khác nhau.
Thí dụ. Sử dụng giá trị của phương thức lọc để xóa các phần tử khỏi mảng JavaScript.
jav
Original array: pop, splice, filter, shift Array Length: 03
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop57
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop0
Removed element: shift Remaining elements: splice, filter, pop60
Removed element: shift Remaining elements: splice, filter, pop2
Removed element: shift Remaining elements: splice, filter, pop62
Removed element: shift Remaining elements: splice, filter, pop63
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 080
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop0
Removed element: shift Remaining elements: splice, filter, pop1
Removed element: shift Remaining elements: splice, filter, pop2
Removed element: shift Remaining elements: splice, filter, pop3
Removed element: shift Remaining elements: splice, filter, pop72
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 090____875
Removed element: shift Remaining elements: splice, filter, pop76
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 080
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 082
Original array: pop, splice, filter, shift Array Length: 092
đầu ra.
Original array: pop, splice, filter, shift Array Length: 06
Loại bỏ các phần tử mảng bằng cách sử dụng Phương thức loại bỏ. Tạo phương thức xóa bằng phương thức lọc để xóa phần tử khỏi mảng JavaScript. Phương pháp này hoạt động theo thứ tự ngược lại.
Thí dụ.
jav
Original array: pop, splice, filter, shift Array Length: 03
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 086
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 089
Removed element: shift Remaining elements: splice, filter, pop88
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop90
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop92
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop94
Original array: pop, splice, filter, shift Array Length: 067
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop98
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop0
Original array: pop, splice, filter, shift Array Length: 0901
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 0903
Removed element: shift Remaining elements: splice, filter, pop62
Original array: pop, splice, filter, shift Array Length: 0905
Removed element: shift Remaining elements: splice, filter, pop0
Original array: pop, splice, filter, shift Array Length: 0907
Original array: pop, splice, filter, shift Array Length: 0908
Removed element: shift Remaining elements: splice, filter, pop62
Original array: pop, splice, filter, shift Array Length: 0910
Original array: pop, splice, filter, shift Array Length: 0903
Original array: pop, splice, filter, shift Array Length: 0912
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 097
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 0919
Removed element: shift Remaining elements: splice, filter, pop92
Removed element: shift Remaining elements: splice, filter, pop10
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 097
Original array: pop, splice, filter, shift Array Length: 0925
Original array: pop, splice, filter, shift Array Length: 083
đầu ra.
Original array: pop, splice, filter, shift Array Length: 00
Xóa phần tử mảng bằng toán tử Delete. Sử dụng toán tử xóa để xóa các phần tử khỏi mảng JavaScript.
Thí dụ.
jav
Original array: pop, splice, filter, shift Array Length: 03
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 086
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 089
Removed element: shift Remaining elements: splice, filter, pop88
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop90
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop92
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop94
Original array: pop, splice, filter, shift Array Length: 067
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 0943
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 0946
Original array: pop, splice, filter, shift Array Length: 0947
Original array: pop, splice, filter, shift Array Length: 0948
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 0952
Original array: pop, splice, filter, shift Array Length: 0953
Original array: pop, splice, filter, shift Array Length: 093
Removed element: shift Remaining elements: splice, filter, pop10
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 097
Original array: pop, splice, filter, shift Array Length: 0959
Original array: pop, splice, filter, shift Array Length: 0960
đầu ra.
Original array: pop, splice, filter, shift Array Length: 09
Loại bỏ các phần tử mảng bằng toán tử xóa và đặt lại. Sử dụng toán tử xóa và đặt lại để xóa các phần tử khỏi mảng JavaScript
ví dụ 1.
jav
Original array: pop, splice, filter, shift Array Length: 03
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 086
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 089
Removed element: shift Remaining elements: splice, filter, pop88
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop90
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop92
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop94
Original array: pop, splice, filter, shift Array Length: 067
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 0977
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 0980
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04____1983
Original array: pop, splice, filter, shift Array Length: 04____1985
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 090
Removed element: shift Remaining elements: splice, filter, pop52
Original array: pop, splice, filter, shift Array Length: 002
Original array: pop, splice, filter, shift Array Length: 093
Original array: pop, splice, filter, shift Array Length: 004
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 001
Original array: pop, splice, filter, shift Array Length: 0995
Removed element: shift Remaining elements: splice, filter, pop23
đầu ra.
Original array: pop, splice, filter, shift Array Length: 09
ví dụ 2.
jav
Original array: pop, splice, filter, shift Array Length: 03
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 086
Original array: pop, splice, filter, shift Array Length: 04
Removed element: shift Remaining elements: splice, filter, pop3
Original array: pop, splice, filter, shift Array Length: 089
Removed element: shift Remaining elements: splice, filter, pop88
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop90
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop92
Removed element: shift Remaining elements: splice, filter, pop6
Removed element: shift Remaining elements: splice, filter, pop94
Original array: pop, splice, filter, shift Array Length: 067
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 001
Original array: pop, splice, filter, shift Array Length: 002
Original array: pop, splice, filter, shift Array Length: 093
Original array: pop, splice, filter, shift Array Length: 004
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 0920
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 0922
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 090
Removed element: shift Remaining elements: splice, filter, pop52
Removed element: shift Remaining elements: splice, filter, pop53
Original array: pop, splice, filter, shift Array Length: 0927
đầu ra.
Original array: pop, splice, filter, shift Array Length: 00
Xóa các phần tử Array bằng vòng lặp for[] đơn giản và một mảng mới. Ở đây, một for[] đơn giản sẽ được chạy trên mảng và ngoại trừ phần tử bị loại bỏ, các phần tử còn lại sẽ được đẩy vào mảng mới sẽ được khai báo bên trong hàm hoặc phương thức
Thí dụ
Javascript
Original array: pop, splice, filter, shift Array Length: 072
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 0930
Original array: pop, splice, filter, shift Array Length: 0931
Original array: pop, splice, filter, shift Array Length: 0932
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 0931
Original array: pop, splice, filter, shift Array Length: 093
Original array: pop, splice, filter, shift Array Length: 0936
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 098
Original array: pop, splice, filter, shift Array Length: 0939
Original array: pop, splice, filter, shift Array Length: 0940
Original array: pop, splice, filter, shift Array Length: 0941
Removed element: shift Remaining elements: splice, filter, pop2
Original array: pop, splice, filter, shift Array Length: 097
Original array: pop, splice, filter, shift Array Length: 0931
Original array: pop, splice, filter, shift Array Length: 097
Original array: pop, splice, filter, shift Array Length: 0931
Removed element: shift Remaining elements: splice, filter, pop62
Original array: pop, splice, filter, shift Array Length: 0948
Original array: pop, splice, filter, shift Array Length: 04____1950
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 0953
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 0955
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 0957
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 090
Original array: pop, splice, filter, shift Array Length: 097
Original array: pop, splice, filter, shift Array Length: 0962
Original array: pop, splice, filter, shift Array Length: 08
Original array: pop, splice, filter, shift Array Length: 04
Original array: pop, splice, filter, shift Array Length: 0965
Original array: pop, splice, filter, shift Array Length: 092
đầu ra
Original array: pop, splice, filter, shift Array Length: 01
Xóa các phần tử Mảng bằng thư viện lowdash. Sử dụng thư viện lowdash để xóa các phần tử khỏi mảng JavaScript. Để sử dụng thư viện lowdash, bạn cần cài đặt nó cục bộ trên hệ thống của mình