JS Built-ins
ControlFlowadvanced

Control Flow β€” nested loops: searching a matrix

Nested loops iterate over 2D structures

A loop inside a loop visits every combination of indices. Break from the inner loop to stop early.

Challenge: Write findInMatrix(matrix, target) that searches a 2D array and returns [row, col] of the first match, or null if not found.

πŸ’‘ Hints (1)
  • β€’ Return [i, j] immediately when matrix[i][j] === target