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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:46:24+00:00 2026-05-23T09:46:24+00:00

I am trying to create a set of buttons that behave like a list,

  • 0

I am trying to create a set of buttons that behave like a list, where an array is created from the values selected.

Below is the function for checking if the value already exists in the array, and if it does not it will not add the new value.

function linearSearch(arrayName, sValue) 
{               
    Array.prototype.exists = function(search){
      for (var i=0; i<this.length; i++)
        if (this[i] == search) return true;

      arrayName.push(sValue);
      return false;
    } 
}

Here is the jquery click function (of the listed items) where this function is called:

    con_array = [];
    $('.con_button').live('click', function (e) {
        e.stopPropagation()                              
        $(this).html('<div class="fun_button_center"></div>');
        con_value = $(this).attr('data-value');
        linearSearch(con_array, con_value);
        alert(con_array);
    });

The function works perfectly fine if it is inside of the click function without parameters. Yet in this circumstance, where it would be optimal because I can reuse it, no value is displayed with alert(con_array);

  • 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-23T09:46:24+00:00Added an answer on May 23, 2026 at 9:46 am

    At the very least, write your `linearSearch function this way:

    function linearSearch(arrayName, sValue) 
    {               
        Array.prototype.exists = function(search){
          for (var i=0; i<this.length; i++)
            if (this[i] == search) return true;
        };
    
        if (arrayName.exists(sValue) return true;
    
        arrayName.push(sValue);
        return false;     
    }
    

    It’s brittle to monkey-patch Array this way, though, so you can either monkey-patch it at global scope (still ugly, but at least it’s both faster and available everywhere:

    Array.prototype.exists = function(search){
      for (var i=0; i<this.length; i++)
        if (this[i] == search) return true;
    };
    
    function linearSearch(arrayName, sValue) 
    {    
        if (arrayName.exists(sValue) return true;
    
        arrayName.push(sValue);
        return false;     
    }
    

    Or you can just inline that loop:

    function linearSearch(arrayName, sValue) 
    {    
        for (var i=0; i<arrayName.length; i++)
          if (arrayName[i] == sValue) return true;
    
        arrayName.push(sValue);
        return false;     
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a Window using PyGTK that has dynamically created radio buttons
I'm trying to create a Set that contains instances of 'Vertex3<T>'. I'm having a
I'm trying to create a set of checkboxes that I can check and send
I am trying to create an android app that has the following: Theme set
I'm trying to create a string that has a set amount of different words
ok so im trying to create a macro that will take my set cells
I'm trying to create a view that's full of controls (buttons, text views, labels,
I am attempting to create a Tab Control Style that basically looks like buttons
I am trying to create a GUI that allows someone to set up an
I am trying to change the name of a set of radio buttons that

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.