เมธอด map() ของออบเจ็กต์ TypedArray รับฟังก์ชัน callback เรียกใช้กับแต่ละองค์ประกอบของ typed array และส่งคืน TypedArray ใหม่ที่มีผลลัพธ์
ไวยากรณ์ (Syntax)
typedArray.map(callbackFn)
ตัวอย่าง
<html> <head> <title>ตัวอย่าง JavaScript</title> </head> <body> <script type="text/javascript"> var int32View = new Int32Array([11, 5, 13, 4, 15, 3, 17, 2, 19, 8 ]); document.write("เนื้อหาของ typed array: "+int32View); document.write("<br>"); function square(ele) { return ele*ele; } var result = int32View.map(square); document.write("ผลลัพธ์หลังยกกำลังสอง: "+result); </script> </body> </html>
ผลลัพธ์
เนื้อหาของ typed array: 11,5,13,4,15,3,17,2,19,8 ผลลัพธ์หลังยกกำลังสอง: 121,25,169,16,225,9,289,4,361,64