How to jump out of recursion?

has a tree data structure; suppose there are five branches; now I need to find a node; the node is on the third layer of the first branch; how can the subsequent trees not be traversed after finding this node? That is, jump out of the whole recursion? I wrote a simple test and found that I couldn"t jump out of recursion

.
var arr = [[1,2],[3,4]]
const deep = (arr) => {
    for (let i = 0; i < arr.length; iPP) {
        if (Array.isArray(arr[i])) {
            deep(arr[i])
        } else {
            console.log(arr[i])
            if (arr[i] === 2) return 
        }
    }
}
deep(arr)

or is recursion itself uninterruptible?

Feb.23,2022

add a return value to your deep function, and then loop to determine this value

const deep = arr => {
    for (let i = 0; i < arr.length; iPP) {
        if (Array.isArray(arr[i])) {
            if(deep(arr[i]))
                return true
        } else {
            console.log(arr[i])
            if (arr[i] === 2) return true
        }
    }
    return false
}

there is no situation in which recursion cannot jump out. All recursions can be changed into loops, and all can jump out

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eacade-20f7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eacade-20f7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?