[Solved] JS Error: Uncaught SyntaxError: Illegal return statement

let arr = ['a','b','c']
      for( let i=0;i<=arr.length;i++){
        if (i ==2 ){
          console.log(arr[i])
          return  // error: Uncaught SyntaxError: Illegal return statementcan only be used in functions
        } 
      }

Return can only be used in functions

function run() {
  let a = 1
  if (a == 1) {
    return
  }
  console.log(2); // will not output, return interrupts the execution of the code that follows
}

Read More: