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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:29:29+00:00 2026-06-04T13:29:29+00:00

I’m filling a sitemap array as the user travels through my app. However my

  • 0

I’m filling a sitemap array as the user travels through my app.

However my logic to fill the sitemap is flawed. Here is what I’m doing:

var siteMap = [],
    j = siteMap.length;

$(document).on( "pagebeforechange", function( e, data ) {

    if (j == 0 ){
        // add cause sitemap has no elements
        siteMap.push( { type: "external", data: data });
        } else {
            // loop through the sitemap object
            for ( var i = 0; i < j; i++) {
            // check if element is already stored
            if ( data.toPage == self.options.siteMap[i].data.toPage ){
                break;
                }   
            self.options.siteMap.push( { type: "external", data: data } );
            }           
        }
    }); 

The problem is my break does not work as expected. I wanted to loop through the sitemap and compare the data.toPage (a string like /some/page.html) to what I have already stored. If I find a match the loop should end WITHOUT pushing a new element to the sitemap. However, right now I’m looping and if an element is not found at loop postion(1), the break does not fire and I’m adding an entry on every loop until an entry matches.

Question:
How can I fix the loop, so it only adds an entry if no match exists?

Thanks for help!

EDIT:
This is what I have now:

(function( $, window) {
   $.widget("mobile.multiview",$.mobile.widget, {   
      options: {
         siteMap = {};
         },
      eventBindings: function() {

        $(document).on( "pagebeforechange", function( e, data ) {

            var self = this;
            if (!self.options.siteMap[data.toPage]){
               self.options.siteMap[data.toPage] = { type: "external", data: data };
               }
            });
        }
 }) (jQuery,this);
  • 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-04T13:29:30+00:00Added an answer on June 4, 2026 at 1:29 pm

    You’re loop performs the test on each iteration. Until it finds the thing it’s looking for, it adds the new entry on every iteration.

    What you need to do instead is see whether the element is in the array already, and then add it if not. Better yet, dump the idea of using an array in the first place and just use the “toPage” value as an object property.

    var sitemap = {};
    
    $(document).on( "pagebeforechange", function( e, data ) {
      if (!sitemap[ data.toPage ])
        sitemap[data.toPage] = { type: "external", data: data };
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an array which has BIG numbers and small numbers in it. I
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload

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.