วิธีการ array.values() ของ JavaScript ส่งกลับวัตถุ Array Iterator ใหม่ที่ประกอบด้วยค่าสำหรับแต่ละดัชนีในอาร์เรย์
ไวยากรณ์มีดังนี้ −
arr.values()
ให้เราใช้เมธอด array.values() ใน JavaScript -
ตัวอย่าง
<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<p>Click the button to display the value...</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
function display() {
var arr = ['p', 'q', 'r'];
var res = arr.values();
document.getElementById("test").innerHTML = res.next().value
}
</script>
</body>
</html> ผลลัพธ์

คลิกที่ปุ่ม "ผลลัพธ์" -

ตัวอย่าง
<!DOCTYPE html>
<html>
<body>
<h2>Ranking Points</h2>
<p>Click to display the points...</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
function display() {
var points = ['10', '20', '30', '40', '50'];
document.getElementById("test").innerHTML = (points.values()).next().value
}
</script>
</body>
</html> ผลลัพธ์

คลิกที่ปุ่ม "ผลลัพธ์" -
