[TIL] Array.prototype.some() 이란?

Yuri Lee·2022년 6월 8일
0

Intro

js의 Array.prototype.some() 함수에 대해 알아보도록 하자.

some()

some()메서드는 배열 안의 어떤 요소라도 주어진 판별 함수를 통과하는지를 테스트한다. 빈 배열에서 호출 시 무조건 false를 반환한다.

Syntax

arr.some(callback[, thisArg])

Try

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

// checks whether an element is even
const even = (element) => element % 2 === 0;

console.log(array.some(even));
// expected output: true
const array = [1];

// checks whether an element is even
const even = (element) => element % 2 === 0;

console.log(array.some(even));
// expected output: false
const array = [];
// checks whether an element is even
const even = (element) => element % 2 === 0;

console.log(array.some(even));
// expected output: false

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/some

profile
Step by step goes a long way ✨

0개의 댓글