1.字串取字元
2.數字取個位數
1.字串取字元
mystr = "yiru123";
getstr0 = mystr.charAt(0);
getstr1 = mystr.charAt(1);
getstr2 = mystr.charAt(2);
getstr3 = mystr.charAt(3);
getstr4 = mystr.charAt(4);
getstr5 = mystr.charAt(5);
console.log(mystr);
console.log(getstr0);
console.log(getstr1);
console.log(getstr2);
console.log(getstr3);
console.log(getstr4);
console.log(getstr5);
https://codepen.io/yiruatstudio/pen/oNLaWRJ?editors=1111
2.數字取個位數
X1=762
X2=194
X3 = String(X1+X2);//轉字串
console.log("X3="+X3);//956
x3len = X3.length;//3
console.log("X3長度="+x3len);
X3 = X3.charAt(x3len-1);//3-1=2 (第2個位置)
console.log("個位數為="+X3); //9 [0] 5 [1] 6[2] //可取到個位數
https://codepen.io/yiruatstudio/pen/JjKmbrp?editors=1111
Yiru@Studio - 關於我 - 意如