Math.charAt()

charAt():從一個字符串中返回指定的字符

const anyString = "Brave new world";
console.log(anyString.charAt(0))//"B"
console.log(anyString.charAt(1))//"r"
console.log(anyString.charAt(3))//"v"
console.log(anyString.charAt(4))//"e"
console.log(anyString.charAt(5))//"n"
console.log(anyString.charAt(6))//" "
console.log(anyString.charAt(999))//" "

Math.atan2():靜態方法返回平面中正 x 軸與從 (0, 0) 到點 (x, y) 的射線之間的角度(以弧度為單位)

Math.atan2():靜態方法返回平面中正 x 軸與從 (0, 0) 到點 (x, y) 的射線之間的角度(以弧度為單位)

function calcAngleDegrees(x, y) {
  return Math.atan2(y, x) * 180 / Math.PI;
}

console.log(calcAngleDegrees(5, 5));
// Expected output: 45

console.log(calcAngleDegrees(10, 10));
// Expected output: 45

console.log(calcAngleDegrees(0, 10));
// Expected output: 90

Math.max():查詢最大值

Math.max():查詢最大值

var myArray1 = [1, 5, 6, 2, 3];
var max1 = Math.max(...myArray1);
console.log('max1',max1)
//"max1" 6

function MyMax(myarr){
    var al = myarr.length;
    maximum = myarr[al-1];
    while (al--){
        if(myarr[al] > maximum){
            maximum = myarr[al]
        }
    }
    return maximum;
};

var myArray2 = [1, 5, 8, 2, 3];
var max2 = MyMax(myArray2);
console.log('max2',max2)
//"max2" 8

Math.tan():返回以弧度為單位的數字的正切值

Math.tan():返回以弧度為單位的數字的正切值

function getTanFromDegrees(degrees) {
  return Math.tan(degrees * Math.PI / 180);
}

console.log(getTanFromDegrees(0));
// Expected output: 0

console.log(getTanFromDegrees(45));
// Expected output: 0.9999999999999999

console.log(getTanFromDegrees(90));
// Expected output: 16331239353195370



Math.abs():返回數字的絕對值

Math.abs():將其參數強制為數字。不可強制值將變為NaN,Math.abs()也使得返回NaN

Math.abs("-1"); // 1
Math.abs(-2); // 2
Math.abs(null); // 0
Math.abs(""); // 0
Math.abs([]); // 0
Math.abs([2]); // 2
Math.abs([1, 2]); // NaN
Math.abs({}); // NaN
Math.abs("string"); // NaN
Math.abs(); // NaN

Math.atan()

Math.atan():// 以弧度計算直角三角形的角度

function calcAngle(opposite, adjacent) {
  return Math.atan(opposite / adjacent);
}


console.log(calcAngle(8, 10));
// Expected output: 0.6747409422235527

console.log(calcAngle(5, 3));
// Expected output: 1.0303768265243125