JavaScript의 array.includes() 메서드는 배열에 지정된 요소가 포함되어 있는지 확인하는 데 사용됩니다.
구문은 다음과 같습니다 -
array.includes(ele, start)
위에서 ele 매개변수는 검색할 요소입니다. 시작 매개변수는 검색을 시작할 위치입니다.
이제 JavaScript에서 array.includes() 메서드를 구현해 보겠습니다.
예시
<!DOCTYPE html>
<html>
<body>
<h2>Car Variant</h2>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
var carid = ["110", "230", "299", "399"];
document.getElementById("test").innerHTML = carid;
function display() {
var n = carid.includes("230");
document.getElementById("test").innerHTML = "The array has the specific value 230? = "+n;
}
</script>
</body>
</html> 출력

위의 "결과" 버튼 클릭 -

예시
<!DOCTYPE html>
<html>
<body>
<h2>Car Variant</h2>
<p>Does the array includes the specific element Crossover?</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
var car = ["Hatchback", "Convertible"];
var res2 = car.entries();
for (val of res2) {
document.getElementById("test").innerHTML += val + "<br>";
}
function display() {
var res = car.includes("Crossover");
document.getElementById("test").innerHTML = res;
}
</script>
</body>
</html> 출력

위의 "결과" 버튼을 클릭하십시오 -
