ฟังก์ชัน include() ของอ็อบเจ็กต์ TypedArray ยอมรับค่าและตรวจสอบว่าอาร์เรย์ที่พิมพ์นี้มีองค์ประกอบที่ระบุหรือไม่ หากอาร์เรย์มีองค์ประกอบที่กำหนด ก็จะคืนค่า จริง มิฉะนั้น จะส่งคืนค่า เท็จ
ไวยากรณ์
ไวยากรณ์ของมันคือดังต่อไปนี้
typedArray.includes()
ตัวอย่าง
<html>
<head>
<title>JavaScript Array every Method</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([21, 19, 65, 21, 14, 66, 87, 55 ]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
var contains = int32View.includes(66);
if(contains) {
document.write("Array contains the specified element");
}else {
document.write("Array doesn’t contains the specified element");
}
</script>
</body>
</html> ผลลัพธ์
Contents of the typed array: 21,19,65,21,14,66,87,55 Array contains the specified element
ตัวอย่าง
<html>
<head>
<title>JavaScript Array every Method</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([21, 19, 65, 21, 14, 66, 87, 55 ]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
var contains = int32View.includes(762);
if(contains) {
document.write("Array contains the specified element");
}else {
document.write("Array doesn’t contains the specified element");
}
</script>
</body>
</html> ผลลัพธ์
Contents of the typed array: 21,19,65,21,14,66,87,55 Array doesn’t contains the specified element