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

  • Home
  • SEARCH
  • 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 9301701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:05:27+00:00 2026-06-18T23:05:27+00:00

I have a grid based game 8 squares by 8 squares giving 64 pieces

  • 0

I have a grid based game 8 squares by 8 squares giving 64 pieces in total, these pieces are stored in an array. I’m having a problem where certain grid squares are being populated twice so I need to check the array for duplicate co-ordinates.

Below code gives the x, y grid co-ordinates of each piece – testX and testY, I’m not sure how I would go about running through this array to remove duplicates. If there are duplicates pieces I need to keep the first encountered and remove any subsequent duplicates. I’m using jQuery if that helps.

function checkGrid() {

    var x;

    for (x = 0; x < grid.length; x++) {

    var testY= grid[x].getY();
    var testX = grid[x].getX();

    }
}
  • 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-18T23:05:29+00:00Added an answer on June 18, 2026 at 11:05 pm

    You could consider using an object instead of an array:

    var grid = {};
    
    function setGridValue(x,y, value){
        var key = x + '-' + y;
        grid[key] = value;
    }
    
    function getGridValue(x,y){
        var key = x + '-' + y;
        return grid[key];
    }
    

    Something like this. Then if you change the value of a grid location, you don’t need to check for duplicates.

    EDIT.

    Since you can’t change to object, you should find an existing item when you insert them. You didn’t post the code where you add items to the grid, but can you do something like this:

    function setItem(x, y, value){
       var item;
       // check for existing item in array
       for(var i = 0; i < grid.length; i++){
           if(grid[i].getX() === x && grid[i].getY() === y){
               item = grid[i];
               break;
           }
       }
       // if no existing item, create new one
       if(!item){
          item = new GridItem(x,y,value);  // dont know what is in the grid...
          grid.push(item);
       } else {
          // update existing item here...
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a game that is based on a grid being populated with
My problem is I Have an isometric grid, just based on the X,Y values:
I have a square grid, for a turn based game ( grid is similar
I'm making a grid-based game where you have land and water and the land
I'm having a problem with finding N positions in a grid based on a
If I'm making a simple grid based game, for example, I might have a
I have recently been working on a small top-down grid-based 2D game. As part
I have a schedule grid based on a HTML table using jQuery/jQuery UI drag
I have a grid that is dynamically generated based on search criteria. I render
In my project I have a grid view which contains images. Based on my

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.