JavaScript의 array.entries() 메서드는 키/값 쌍이 있는 Array Iterator 객체를 반환하는 데 사용됩니다.
구문은 다음과 같습니다 -
array.entries()
이제 JavaScript에서 array.entries() 메서드를 구현해 보겠습니다. -
예시
<!DOCTYPE html>
<html>
<body>
<h2>Ranking Points</h2>
<p>Is any point equal to 550 from the key-value pairs...</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
var pointsArr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 1000];
var res = pointsArr.entries();
for (val of res) {
document.getElementById("test").innerHTML += val + "<br>";
}
function pointsFunc(points) {
return points == 550;
}
function display() {
document.getElementById("test").innerHTML = pointsArr.some(pointsFunc);
}
</script>
</body></html> 출력

"결과" 클릭 -

예시
<!DOCTYPE html>
<html>
<body>
<h2>Car Variant</h2>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
var car = ["Hatchback", "Convertible", "SUV", "AUV", "MUV"];
var res = car.entries();
for (val of res) {
document.getElementById("test").innerHTML += val + "<br>";
}
function display() {
document.getElementById("test").innerHTML = "Array after slicing some elements = "+car.slice(1,4);
}
</script>
</body>
</html> 출력

"결과" 버튼 클릭 -
