Js循环案例

1、写九九乘法表

1、for循环
for (let i = 1; i < 10; i++) {
    for (let j = 1; j <= i; j++) {
        document.write(`${j}*${i}=${i * j}`);
    }
    document.write(`
`) } 2、while循环 let i = 1 while(i < 10){ let j = 1 while(j <= i){ document.write(`${j}*${i}=${i * j}`) j++ } document.write(`
`) i++ }

2、遍历二维数组

let arr1=[[1,2,3,4],["小明","小红","小宋","小白"],['red','orange','green','blue']]
for(let i in arr1) {
    for(let j in arr1[i]){
        document.write(arr1[i][j])
        document.write(`
`) } }

你可能感兴趣的:(笔记,javascript,前端,java)