Hàm filter() của TypedArray tạo một TypedArray mới chứa tất cả các phần tử thỏa mãn điều kiện do hàm callback cung cấp. Mảng gốc không thay đổi.
Cú pháp
Cú pháp của nó như sau:
typedArray.filter(callbackFn[, thisArg])
Ví dụ
<html> <head> <title>Ví dụ JavaScript TypedArray filter</title> </head> <body> <script type="text/javascript"> var int32View = new Int32Array([64, 89, 65, 21, 14, 66, 87, 55]); document.write("Nội dung mảng typed: "+int32View); document.write("<br>"); function testResult(element, index, array) { return element > 35; } var result = int32View.filter(testResult); document.write("Các phần tử lớn hơn 35: "+result); </script> </body> </html>
Kết quả
Nội dung mảng typed: 64,89,65,21,14,66,87,55 Các phần tử lớn hơn 35: 64,89,65,66,87,55