Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

ฟังก์ชัน TypedArray.includes() ใน JavaScript


ฟังก์ชัน includes() ของออบเจ็กต์ TypedArray จะรับค่าและตรวจสอบว่า Typed Array นั้นมีองค์ประกอบที่ระบุอยู่หรือไม่ หากอาร์เรย์มีองค์ประกอบดังกล่าว จะคืนค่า true มิฉะนั้นจะคืนค่า false

ไวยากรณ์

ไวยากรณ์มีดังนี้

typedArray.includes(ค่าที่ต้องการตรวจสอบ)

ตัวอย่าง

<html> <head>    <title>ตัวอย่าง TypedArray includes</title> </head> <body>    <script type="text/javascript">       var int32View = new Int32Array([21, 19, 65, 21, 14, 66, 87, 55 ]);       document.write("เนื้อหาของ Typed Array: " + int32View);       document.write("<br>");       var contains = int32View.includes(66);       if(contains) {          document.write("อาร์เรย์มีองค์ประกอบที่ระบุ");       } else {          document.write("อาร์เรย์ไม่มีองค์ประกอบที่ระบุ");       }    </script> </body> </html>

ผลลัพธ์

เนื้อหาของ Typed Array: 21,19,65,21,14,66,87,55 อาร์เรย์มีองค์ประกอบที่ระบุ

ตัวอย่าง: ไม่พบองค์ประกอบ

<html> <head>    <title>ตัวอย่าง TypedArray includes</title> </head> <body>    <script type="text/javascript">       var int32View = new Int32Array([21, 19, 65, 21, 14, 66, 87, 55 ]);       document.write("เนื้อหาของ Typed Array: " + int32View);       document.write("<br>");       var contains = int32View.includes(762);       if(contains) {          document.write("อาร์เรย์มีองค์ประกอบที่ระบุ");       } else {          document.write("อาร์เรย์ไม่มีองค์ประกอบที่ระบุ");       }    </script> </body> </html>

ผลลัพธ์

เนื้อหาของ Typed Array: 21,19,65,21,14,66,87,55 อาร์เรย์ไม่มีองค์ประกอบที่ระบุ