1. The for loop

let aa = function() {
        for(var i = 0; i < 5; i++) {
            console.log(i)
            if (i == 3) {
                // return
                // break the loop
                // continue // Breaks the current loop
            }
        }
    }
    aa() // 0 1 2 3
Copy the code

2,forEach

  let bb = function () {
        let arr = [1.2.3.4.5]
        arr.forEach(item= > {
            console.log(item)
            if (item == 3) {
                console.log('item')
                // return
                // break // Syntax error
                console.log('return')
            }
        })
    }
    bb() // 1 2 3 item 4 5
Copy the code

Return (break); return (break);

ForEach simply breaks out of the current loop by using a return and uses a break to report a syntax error.