Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8540947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:42:50+00:00 2026-06-11T11:42:50+00:00

I am really having a hard time trying to fill my two dimensional array

  • 0

I am really having a hard time trying to fill my two dimensional array in Javascript.

I have a different array with lots of letters that I want to add to my ‘board’ but even the board dose not seem to be working correctly. Whenever I try to print board to the web page using the draw Board method I get NaN for the place where the letter A is. The rest is displaying the number 0.

var ROW = 10;
var COLUMN = 10;
var board = [['A', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];

function drawBoard(board) {
    var str = '';
    for (var x = 0; x < ROW; x++){
        str += '<div class="row">';
        for (var y = 0; y < COLUMN; y++){
            str += '<div class="column">' +
            + board[x][y] + '</div>' + '</div>';
        }
        str += '</div>';
    }
    $('#board').append(str);
}

$(function(){
    drawBoard(board);
});

What I want to do is have this string:

var Letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'];

make a for loop to just board[x][y] = Letters.pop(). And then display the board with the new letters.

Are there any better ways to add an array to a two dimentional array than just running two for loops?
Why dose my board display NaN and not the letter. I have tried many different things.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:42:51+00:00Added an answer on June 11, 2026 at 11:42 am

    To answer the first question. If you look at your code:

           str += '<div class="column">' +
            + board[x][y] + '</div>' + '</div>';
    

    you can see that you have a + +board[x][y], not a + when adding board[x][y]. The unary + tries to convert the value of board[x][y] to a number before concatenating giving you the NaN error( as @Bergi pointed out).

    To add an element to the end of an array you can use the push() method (in your caseboard.push(Letters)). This will place the element, which can be an array, at the end of the array.

    If you want to replace a line in the array you can use board[x] = Letters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a really hard time getting this to work. I have two
Having a really hard time trying to figure out a where in equivalent in
I'm really having a hard time trying to figure out what's going on here.
I'm having a really hard time trying to figure out how to store or
I am having a really hard time trying to get this to work. All
I am new to iPhone programming and am having a really hard time trying
I'm having a really hard time when trying to cancel requests in an NSOperationQueue.
I'm having a really hard time trying to get the infowindows in Google Maps
I'm having a really hard time to recover from configuration changes with ViewPager .
I'm having a really hard time understanding delegates and object inheritance (if I may

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.