本帖最後由 陳育霖 於 2023-9-2 07:49 編輯
for 迴圈- var n = document.getElementById("number");
- var sum = 0;
- for (i = 1; i <= n; i++){
- sum += number;
- }
- document.getElementById("total").innerHTML = sum;
複製代碼 while 迴圈- var n = document.getElementById("number");
- var sum = 0;
- var i = 1;
- while(i <= n){
- sum += i;
- }
- document.getElementById("total").innerHTML = sum;
複製代碼 陣列- var numbers = [1, 2, 3, 4, 5];
- var sorted = numbers.sort();
- var arr_length = numbers.length;
- numbers.push(10);
- numbers.unshift(0);
- numbers.pop();
- numbers.shift();
- numbers.slice(index, length);
- numbers.splice(index, length, 'word');
複製代碼 |