Modelo

  • EN
    • English
    • Español
    • Français
    • Bahasa Indonesia
    • Italiano
    • 日本語
    • 한국어
    • Português
    • ภาษาไทย
    • Pусский
    • Tiếng Việt
    • 中文 (简体)
    • 中文 (繁體)

How to Print a 2D Array in JavaScript

Oct 19, 2024

Hey everyone! Today, I'm going to show you how to print a 2D array in JavaScript using the JSON.stringify method.

Step 1: First, let's create a sample 2D array. You can create a 2D array like this:

```javascript

const myArray = [

[1, 2, 3],

[4, 5, 6],

[7, 8, 9]

];

```

Step 2: Now, we can print the 2D array using the JSON.stringify method. Here's how you can do it:

```javascript

console.log(JSON.stringify(myArray));

```

Step 3: When you run the code, you will see the 2D array printed as a JSON string in the console. It will look something like this:

```

[[1,2,3],[4,5,6],[7,8,9]]

```

And that's it! You've successfully printed a 2D array in JavaScript using the JSON.stringify method. Give it a try and let me know how it goes! Thanks for watching!}

Recommend