ฟังก์ชัน acos() ของออบเจกต์ Math ยอมรับตัวเลขและส่งกลับค่าโคไซน์ของส่วนโค้งเป็นเรเดียน หากต้องการแปลงค่าผลลัพธ์เป็นองศา ให้คูณด้วย 180 แล้วหารผลลัพธ์ด้วย 3.14159 (ค่า pi)
ไวยากรณ์
ไวยากรณ์ของมันคือดังต่อไปนี้
Math.acos(0.5)
ตัวอย่าง
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var result = Math.acos(0.5);
document.write("arccosine value: "+result);
document.write("<br>");
document.write("arccosine value in degrees: "+result*180/Math.PI);
</script>
</body>
</html> ผลลัพธ์
arccosine value: 1.0471975511965979 arccosine value in degrees: 60.00000000000001