JavaScript Array some() 함수는 배열의 일부 요소가 주어진 테스트를 통과하는지 여부를 확인합니다. 테스트는 기본적으로 배열의 각 요소에 대해 실행되는 함수입니다.
다음은 배열 some() 메서드에 대한 코드입니다. -
예시
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.sample {
font-size: 20px;
font-weight: 500;
}
</style>
</head>
<body>
<h1>JavaScript Array some()</h1>
<div class="sample"></div>
<button class="Btn">CLICK HERE</button>
<h3>
Click on the above button to see if some multiples of 11 are present in
array or not
</h3>
<script>
function checkMultiple(ele) {
if (ele % 11 == 0) return true;
}
let fillEle = document.querySelector(".sample");
let arr = [22, 19, 55, 12, 14];
fillEle.innerHTML = arr;
document.querySelector(".Btn").addEventListener("click", () => {
fillEle.innerHTML = "Multiples of 11 present: " + arr.some(checkMultiple);
});
</script>
</body>
</html> 출력

"여기를 클릭" 버튼을 클릭하면 -
