CodesJava

Easy learning with example program codes

TypedArray includes() JavaScript

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

Syntax:

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 return false.

Example 1:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">  
var Jewels = ["DIAMOND","GOLD","PLATINUM","SILVER"];  
result = Jewels.includes("GOLD")  
document.write(result);  
</script>
</body>
</html>

Output:

true

Example 2:

<!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>

Output:

true
false
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status