ฟังก์ชัน fill() ของวัตถุ TypedArray แทนที่องค์ประกอบที่จำเป็น/ต้องการทั้งหมดของอาร์เรย์ด้วยการระบุค่า (คงที่) ฟังก์ชันนี้ยอมรับตัวเลขสามตัว ตัวหนึ่งแทนค่าคงที่ และอีกสองตัวแสดงดัชนีเริ่มต้นและจุดสิ้นสุดของส่วนขององค์ประกอบที่จะแทนที่ (ค่าสิ้นสุดเป็นทางเลือก)
ไวยากรณ์
ไวยากรณ์ของมันคือดังต่อไปนี้
int32View.fill(464, 3);
ตัวอย่าง
<html>
<head>
<title>JavaScript Array every Method</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([64, 89, 65,21, 14, 66, 87, 55]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
result = int32View.fill(464, 3);
document.write("Contents of the typed array after fill: "+int32View);
</script>
</body>
</html> ผลลัพธ์
Contents of the typed array: 64,89,65,21,14,66,87,55 Contents of the typed array after fill: 64,89,65,464,464,464,464,464