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 856899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:18:43+00:00 2026-05-15T08:18:43+00:00

To begin with, I have a database that holds map data for a game

  • 0

To begin with, I have a database that holds map data for a game I am creating. A script on my page uses JSON to retrieve a certain amount of that data from the database and store it in an array.

When the data is retrieved it goes through a function that finds out how many individual tiles are used in that particular area. Here is the code:

var xmlhttp = new XMLHttpRequest;
xmlhttp.onreadystatechange = function(){
    if(xmlhttp.readyState == 4){
        var map = JSON.parse(xmlhttp.responseText);
        var mapTiles = new Array;
        for(var count = 0; count < map.length; count ++){
            if(map[count]){
                if(map[count]['tile'] in mapTiles == false){
                    mapTiles.push(map[count]['tile']);
                }
            }
        }
        alert(mapTiles);
    }
}

For each time the script finds a tile number that isn’t already in the mapTiles array it adds it to it.

Currently, the script is fetching 1024 records that all but one contain the tile value of ‘1’ the other of which contains the tile value of ‘2’. This means that when I alert the mapTiles array it should display “1, 2” but instead it displays “1, 1, 2”. So there is a slight error in the script but I cannot find it.

  • 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-05-15T08:18:44+00:00Added an answer on May 15, 2026 at 8:18 am

    The in operator checks to see if the object has the named property or contains an element at the array index. In your case, the check is always false because the first time, there are no elements and so it returns false. When mapTiles contains 1 it’s in the zeroth position and thus the check returns false. When you check for 2, the last element is in the first position and thus it returns false. You need to iterate through the array and check for the value of the element, rather than use the in operator.

     function contains( obj, aray )
     {
          for (var i = 0, len = aray.length, isIn = false; i < len && !isIn; ++i) {
              isIn = aray[i] === obj;
          }
          return isIn;
     }
    
    
     ...
     if(!contains(map[count]['tile'],mapFiles)){
         mapTiles.push(map[count]['tile']);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 496k
  • Answers 496k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is no way to kill an application with the… May 16, 2026 at 11:31 am
  • Editorial Team
    Editorial Team added an answer I modified table.tagx so it could be used with sub-properties… May 16, 2026 at 11:31 am
  • Editorial Team
    Editorial Team added an answer I found a solution to my problem at http://www.iphonedevsdk.com/forum/iphone-sdk-development/1388-getting-actual-content-size-uiwebview.html I'm… May 16, 2026 at 11:31 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have an arraylist that holds a subset of names found in my database.
I have a SQL Server that houses Several Databases. I have a Main Database
I have a new Visual Studio 2008 Database Project (Data Dude). It was generated
I'm using Visual Studio 2005 to script out a database so that I can
I have a question, but let me first say that this is being performed
We're using SQLAlchemy declarative base and I have a method that I want isolate
You have been so helpful in the past that I keep coming back searching
I'm using SQLite in an Android application. In all of my tables I have
Within our unit tests we use plain ADO.NET (DataTable, DataAdapter) for preparing the database
I am trying to test a proof of concept that I can run a

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.