Hàm forEach() của TypedArray thực thi một hàm callback cho mỗi phần tử trong mảng, theo thứ tự chỉ số. Hàm callback nhận (element, index, array). Không trả về giá trị (undefined).
Cú pháp
Cú pháp của nó như sau:
typedArray.forEach(callbackFn[, thisArg])
Ví dụ
<html> <head> <title>Ví dụ JavaScript TypedArray forEach</title> </head> <body> <script type="text/javascript"> var int32View = new Int32Array([21, 19, 65, 21, 14, 66, 87, 55]); document.write("Nội dung mảng typed: "+int32View); document.write("<br>"); document.write("Kết quả: "); function testResult(element, index, array) { document.write(element + 100 + " "); } int32View.forEach(testResult); </script> </body> </html>
Kết quả
Nội dung mảng typed: 21,19,65,21,14,66,87,55 Kết quả: 121 119 165 121 114 166 187 155