0
0
DSA Javascriptprogramming~30 mins

Search in 2D Matrix in DSA Javascript - Build from Scratch

Choose your learning style9 modes available
Search in 2D Matrix
📖 Scenario: You are working with a grid-like map that stores numbers in rows and columns. You want to find if a specific number exists in this map.
🎯 Goal: Build a program that searches for a given number in a 2D matrix and tells if it is found or not.
📋 What You'll Learn
Create a 2D array called matrix with exact values
Create a variable called target with the number to search
Use nested for loops with variables i and j to search the matrix
Print "Found" if target is in matrix, otherwise print "Not Found"
💡 Why This Matters
🌍 Real World
Searching in a 2D matrix is like looking for a seat in a theater or a book in a shelf arranged in rows and columns.
💼 Career
Understanding how to search in 2D data structures is important for jobs involving data analysis, game development, and software engineering.
Progress0 / 4 steps
1
Create the 2D matrix
Create a 2D array called matrix with these exact rows: [1, 3, 5], [7, 9, 11], [13, 15, 17]
DSA Javascript
Hint

Use square brackets to create arrays inside an array.

2
Set the target number to search
Create a variable called target and set it to 9
DSA Javascript
Hint

Use const to create the variable and assign the number 9.

3
Search for the target in the matrix
Use nested for loops with variables i and j to check each element in matrix. Create a variable called found set to false before the loops. If matrix[i][j] equals target, set found to true and break both loops.
DSA Javascript
Hint

Use two loops: outer for rows (i), inner for columns (j). Use break to stop loops when found.

4
Print the search result
Print "Found" if found is true, otherwise print "Not Found"
DSA Javascript
Hint

Use console.log to print the result based on the found variable.