TypedArray.set()
เมธอด set() คัดลอกค่าจาก Array หรือ Typed Array อื่น เข้ามาใน Typed Array ปัจจุบัน เริ่มต้นที่ Index ที่กำหนด
ไวยากรณ์
typedArray.set(sourceArray, offset)
ตัวอย่าง
<html> <body> <script>
var typedArray1 = new Int32Array([11, 5, 13, 4, 15, 3, 17, 2, 19, 8]);
document.write("Contents of the typed array: " + typedArray1);
document.write("<br>");
var typedArray2 = new Int32Array([110, 215, 316, 916, 616, 117, 311]);
typedArray1.set(typedArray2, 3); // เริ่มวางที่ Index 3
document.write("Result: " + typedArray1);
</script> </body> </html>
ผลลัพธ์
Contents of the typed array: 11,5,13,4,15,3,17,2,19,8 Result: 11,5,13,110,215,316,916,616,117,311
คำอธิบาย: ค่าของ typedArray2 ถูกคัดลอกเข้า typedArray1 เริ่มที่ Index 3 แทนที่ค่าเดิม 4,15,3,17,2,19,8 ด้วย 110,215,316,916,616,117,311