| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/findIndex | [Back] [Original] |
Get to know MDN better
function isNegative(element, index, array) {
return element < 0;
}
const int8 = new Int8Array([10, -20, 30, -40, 50]);
console.log(int8.findIndex(isNegative));
// : 1
findIndex(callbackFn)
findIndex(callbackFn, thisArg)
-1
-1
function isPrime(n) {
if (n < 2) {
return false;
}
if (n % 2 === 0) {
return n === 2;
}
for (let factor = 3; factor * factor <= n; factor += 2) {
if (n % factor === 0) {
return false;
}
}
return true;
}
const uint8 = new Uint8Array([4, 6, 8, 12]);
const uint16 = new Uint16Array([4, 6, 7, 12]);
console.log(uint8.findIndex(isPrime)); // -1, not found
console.log(uint16.findIndex(isPrime)); // 2
| ECMAScript 2027 LanguageSpecification # sec-%typedarray%.prototype.findindex |
| Web Proxy Viewer | New URL | Original Page |