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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:57:14+00:00 2026-05-28T15:57:14+00:00

related (sort of) to this question. I have written a script that will loop

  • 0

related (sort of) to this question. I have written a script that will loop through an object to search for a certain string in the referring URL. The object is as follows:

var searchProviders = {
  "google": "google.com",
  "bing": "bing.com",
  "msn": "search.msn",
  "yahoo": "yahoo.co",
  "mywebsearch": "mywebsearch.com",
  "aol": "search.aol.co",
  "baidu": "baidu.co",
  "yandex": "yandex.com"
};

The for..in loop I have used to loop through this is:

for (var mc_u20 in mc_searchProviders && mc_socialNetworks) { 
    if(!mc_searchProviders.hasOwnProperty(mc_u20)) {continue;}
    var mc_URL = mc_searchProviders[mc_u20];
    if (mc_refURL.search(mc_URL) != -1) {
        mc_trackerReport(mc_u20);
        return false;
    }

Now I have another object let’s call it socialNetworks which has the following construct:

var socialNetworks = {"facebook" : "facebook.co" }

My question is, can I loop through both of these objects using just one function? the reason I ask is the variable mc_u20 you can see is passed back to the mc_trackerReport function and what I need is for the mc_u20 to either pass back a value from the searchProviders object or from the socialNetworks object. Is there a way that I can do this?

EDIT: Apologies as this wasn’t explained properly. What I am trying to do is, search the referring URL for a string contained within either of the 2 objects. So for example I’m doing something like:

var mc_refURL = document.referrer +'';

And then searching mc_refURL for one of the keys in the object, e.g. "google.com", "bing.com" etc. 9this currently works (for just one object). The resulting key is then passed to another function. What I need to do is search through the second object too and return that value. Am I just overcomplicating 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-05-28T15:57:15+00:00Added an answer on May 28, 2026 at 3:57 pm

    If I understand your question correctly, you have a variable mc_refURL which contains some URL. You want to search through both searchProviders and socialNetworks to see if that URL exists as a value in either object, and if it does you want to call the mc_trackerReport() function with the property name that goes with that URL.

    E.g., for mc_refURL === "yahoo.co" you want to call mc_trackerReport("yahoo"), and for mc_ref_URL === "facebook.co" you want to call mc_trackerReport("facebook").

    You don’t say what to do if the same URL appears in both objects, so I’ll assume you want to use whichever is found first.

    I wouldn’t create a single merged object with all the properties, because that would lose information if the same property name appeared in both original objects with a different URL in each object such as in an example like a searchProvider item "google" : "google.co" and a socialNetworks item "google" : "plus.google.com".

    Instead I’d suggest making an array that contains both objects. Loop through that array and at each iteration run your original loop. Something like this:

    var urlLists = [
           mc_searchProviders,
           mc_socialNetworks
        ],
        i,
        mc_u20;
    
    for (i = 0; i < urlLists.length; i++) {
       for (mc_u20 in urlLists[i]) { 
          if(!urlLists[i].hasOwnProperty(mc_u20))
             continue;
          if (mc_refURL.search(urlLists[i][mc_u20]) != -1) {
             mc_trackerReport(mc_u20);
             return false;
          }
       }
    }
    

    The array of objects approach is efficient, with no copying properties around or anything, and also if you later add another list of URLs, say programmingForums or something you simply add that to the end of the array.

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

Sidebar

Related Questions

This is related to this question I have a vector of points that will,
This is sort of SQL newbie question, I think, but here goes. I have
This question is related to others I have asked on here, mainly regarding sorting
This question is related to, and based off the script from, this question: How
This is sort of related to a previous, yet so far unsuccessful question of
Is that .NET related? It appears to be a pointer of some sort, what
Related to this question , I decided to check the UDFs in my data
Related to this question: URL characters replacement in JSP with UrlRewrite I want to
Related to this question , what is the best practice for naming a mutex?
Related to: Query Windows Search from Java But this time to use OSX's spotlight

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.