Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptJavaScript typedArray.includes() Method

JavaScript typedArray.includes() Method

The typedArray.includes() is an inbuilt function in JavaScript which is used to check whether a particular element is included by the given typedArray or not and accordingly it returns true and false. 

Syntax:

typedarray.includes(Element, Index);

Parameters: It accepts two parameter which are specified below-

  • Element: It is the element which are being searched in the typedArray.
  • Index: It is the index of the element in the typedArray form where search should start. Its default value is zero (0) and it is optional.

Return value: It returns a boolean value true if the element is present in the given typedArray otherwise returns false.

Example 1:

javascript




// Creating some typedArrays
const A = new Uint8Array([ 1, 2, 3, 4, 5 ]);
const B = new Uint8Array([ 5, 10, 15, 20 ]);
const C = new Uint8Array([ 0, 2, 4, 6,, 8, 10 ]);
const D = new Uint8Array([ 1, 3, 5, 7, 9 ]);
  
// Calling include() function
a = A.includes(2)
b = B.includes(15, 1)
c = C.includes(6)
d = D.includes(9, 1)
  
// Printing true or false, either the element
// is present in the typedArray or not
console.log(a);
console.log(b);
console.log(c);
console.log(d);


Output:

true
true
true
true

Example 2: 

javascript




// Creating some typedArrays
const A = new Uint8Array([ 1, 2, 3, 4, 5 ]);
const B = new Uint8Array([ 5, 10, 15, 20 ]);
const C = new Uint8Array([ 0, 2, 4, 6,, 8, 10 ]);
const D = new Uint8Array([ 1, 3, 5, 7, 9 ]);
  
// Calling include() function
a = A.includes(6)
b = B.includes(21, 1)
c = C.includes(6, 4)
d = D.includes(0)
  
// Printing true or false, either the element
// is present in the typedArray or not
console.log(a);
console.log(b);
console.log(c);
console.log(d);


Output:

false
false
false
false

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments