Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

ฟังก์ชัน TypedArray.forEach() ใน JavaScript


ฟังก์ชัน forEach() ของออบเจ็กต์ TypedArray จะรับฟังก์ชัน callback และเรียกใช้ฟังก์ชันนั้นสำหรับแต่ละองค์ประกอบในอาร์เรย์

ไวยากรณ์

ไวยากรณ์มีดังนี้

typedArray.forEach(callbackFunction)

ตัวอย่าง

<html> <head>    <title>ตัวอย่าง TypedArray forEach</title> </head> <body>    <script type="text/javascript">       var int32View = new Int32Array([21, 19, 65, 21, 14, 66, 87, 55 ]);       document.write("เนื้อหาของ Typed Array: " + int32View);       document.write("<br>");       document.write("ผลลัพธ์: ");       function testResult(element, index, array) {          document.writeln(element + 100);       }       int32View.forEach(testResult);    </script> </body> </html>

ผลลัพธ์

เนื้อหาของ Typed Array: 21,19,65,21,14,66,87,55 ผลลัพธ์: 121 119 165 121 114 166 187 155