[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/some [Back]  [Original]

Array.prototype.some() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Array.prototype.some()

Baseline

20157

some() Array 1 true true false

const array = [1, 2, 3, 4, 5];

// 
const even = (element) => element % 2 === 0;

console.log(array.some(even));
// : true

js
some(callbackFn)
some(callbackFn, thisArg)

callbackFn

element

index

array

some()

thisArg

callbackFn this

callbackFn true false

some() callbackFn callbackFn some() true callbackFn some() false

some() "there exists" false

callbackFn

some() callbackFn callbackFn

  • callbackFn some()
  • callbackFn
  • callbackFn callbackFn

:

some() this length

10

js
function isBiggerThan10(element, index, array) {
  return element > 10;
}

[2, 5, 8, 1, 4].some(isBiggerThan10); // false
[12, 5, 8, 1, 4].some(isBiggerThan10); // true

js
[2, 5, 8, 1, 4].some((x) => x > 10); // false
[12, 5, 8, 1, 4].some((x) => x > 10); // true

includes() true

js
const fruits = ["apple", "banana", "mango", "guava"];

function checkAvailability(arr, val) {
  return arr.some((arrVal) => val === arrVal);
}

checkAvailability(fruits, "grapefruit"); // false
checkAvailability(fruits, "banana"); // true

js
const TRUTHY_VALUES = [true, "true", 1];

function getBoolean(value) {
  if (typeof value === "string") {
    value = value.toLowerCase().trim();
  }

  return TRUTHY_VALUES.some((t) => t === value);
}

getBoolean(false); // false
getBoolean("false"); // false
getBoolean(1); // true
getBoolean("true"); // true

callbackFn 3

array filter() some()

js
const numbers = [3, -1, 1, 4, 1, 5];
const isIncreasing = !numbers
  .filter((num) => num > 0)
  .some((num, idx, arr) => {
    // arr 
    // 
    if (idx === 0) return false;
    return num <= arr[idx - 1];
  });
console.log(isIncreasing); // false

some()

some()

js
console.log([1, , 3].some((x) => x === undefined)); // false
console.log([1, , 1].some((x) => x !== 1)); // false
console.log([1, undefined, 1].some((x) => x !== 1)); // true

some()

some() this length length callbackFn true

js
const arrayLike = {
  length: 3,
  0: "a",
  1: "b",
  2: "c",
  3: 3, // length  3 . some() 
};
console.log(Array.prototype.some.call(arrayLike, (x) => typeof x === "number"));
// false

ECMAScript 2027 LanguageSpecification
# sec-array.prototype.some


Web Proxy Viewer  |  New URL  |  Original Page