TypedArray includes() JavaScript

The JavaScript TypedArray includes() method to check if a particular element is present in the array or not. It is case-sensitive.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
array.includes(searchElement, start)
array.includes(searchElement, start)
array.includes(searchElement, start) 

Parameters:
searchElement: It represents the current element’s value.
start: It represents the index position to start the search.

Returns:
It returns true if the specified element is present in the array, otherwise returns false.

Example 1:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var Jewels = ["DIAMOND","GOLD","PLATINUM","SILVER"];
result = Jewels.includes("GOLD")
document.write(result);
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script type="text/javascript"> var Jewels = ["DIAMOND","GOLD","PLATINUM","SILVER"]; result = Jewels.includes("GOLD") document.write(result); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var Jewels = ["DIAMOND","GOLD","PLATINUM","SILVER"];
result = Jewels.includes("GOLD")
document.write(result);
</script>
</body>
</html>

Example 2:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
const testArray = new Uint8Array([45, 67, 34, 48, 12]);
document.write(testArray.includes(34));
document.write("</br>");
document.write(testArray.includes(34, 3));
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script type="text/javascript"> const testArray = new Uint8Array([45, 67, 34, 48, 12]); document.write(testArray.includes(34)); document.write("</br>"); document.write(testArray.includes(34, 3)); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
const testArray = new Uint8Array([45, 67, 34, 48, 12]);
document.write(testArray.includes(34));
document.write("</br>");
document.write(testArray.includes(34, 3));
</script>
</body>
</html>