typedArray.includes() 是 JavaScript 中的內置函數,用於檢查給定 typedArray 是否包含特定元素,並相應地返回 true 和 false。
用法:
typedarray.includes(Element, Index);
參數:它接受下麵指定的兩個參數 -
- Element:它是在 typedArray 中搜索的元素。
- Index:它是 typedArray 形式中搜索應開始的元素的索引。其默認值為零 (0) 並且是可選的。
返回值:如果該元素存在於給定的 typedArray 中,則返回布爾值 true,否則返回 false。
示例 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);
輸出:
true true true true
示例 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);
輸出:
false false false false
相關用法
- JavaScript typedArray.indexOf()用法及代碼示例
- JavaScript typedArray.keys()用法及代碼示例
- JavaScript typedArray.forEach()用法及代碼示例
- JavaScript typedArray.lastIndexOf()用法及代碼示例
- JavaScript typedArray.sort()用法及代碼示例
- JavaScript typedArray.slice()用法及代碼示例
- JavaScript typedArray.join()用法及代碼示例
- JavaScript typedArray.length()用法及代碼示例
- JavaScript typedArray.fill()用法及代碼示例
- JavaScript typedArray.some()用法及代碼示例
- JavaScript typedArray.reduceRight()用法及代碼示例
- JavaScript typedArray.reduce()用法及代碼示例
- JavaScript typedArray.of()用法及代碼示例
- JavaScript typedArray.set()用法及代碼示例
- JavaScript typedArray.reverse()用法及代碼示例
- JavaScript typedArray.map()用法及代碼示例
- JavaScript typedArray.name屬性用法及代碼示例
- JavaScript trimLeft()用法及代碼示例
- JavaScript trimStart()用法及代碼示例
- JavaScript toUpperCase()用法及代碼示例
- JavaScript toLowerCase()用法及代碼示例
- JavaScript Math cosh()用法及代碼示例
- JavaScript Math sinh()用法及代碼示例
- JavaScript Math sin()用法及代碼示例
- JavaScript Math cos()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 JavaScript typedArray.includes() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。