ฟังก์ชัน values() ของ TypedArray ส่งคืนอ็อบเจ็กต์ iterator ซึ่งเก็บค่าของอาร์เรย์ที่พิมพ์ไว้ เมธอด next() จะคืนค่าองค์ประกอบถัดไปในออบเจกต์ iterator
ไวยากรณ์
ไวยากรณ์ของมันคือดังต่อไปนี้
typedArray.values()
ตัวอย่าง
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var typedArray = new Int32Array([11, 5, 13, 4, 15, 3, 17, 2, 19, 8 ]);
var iterator = typedArray.values();
document.write("Contents of the typed array: ");
for(i=0; i<typedArray.length; i++) {
document.writeln(iterator.next().value);
}
</script>
</body>
</html> ผลลัพธ์
Contents of the typed array: 11 5 13 4 15 3 17 2 19 8