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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:57:39+00:00 2026-06-08T04:57:39+00:00

Using the JQuery autocomplete I have a function that produces an Array of friends

  • 0

Using the JQuery autocomplete I have a function that produces an Array of friends that a user entered in the box.

This array is called selected_Id. However, our project has expanded and along with the ‘friends’ selection (<--the one that produces the selected_Id array)

we would like to add a ‘enemies’ function.

It is possible to rewrite that snippet of code to produce 2 separate arrays? If I keep them separate, it will call the getfriends function twice (the getfriends function produces an array of available friends that loads into the jQuery ui that the user gets to choose from).

here is what I have:

  $(function() {
    var available = new Array();
    available = getFriends();
    available = my_friends
    function split( val ) {
        return val.split( /,\s*/ );
    }
    function extractLast( term ) {
        return split( term ).pop();
    }

    $( "#tags" )
        // don't navigate away from the field on tab when selecting an item
        .bind( "keydown", function( event ) {
            if ( event.keyCode === $.ui.keyCode.TAB &&
                    $( this ).data( "autocomplete" ).menu.active ) {
                event.preventDefault();
            }
        })
        .autocomplete({
            minLength: 0,
            source: function( request, response ) {
                // delegate back to autocomplete, but extract the last term
                response( $.ui.autocomplete.filter(
                    available, extractLast( request.term ) ) );
            },
            focus: function() {
                // prevent value inserted on focus
                return false;
            },
            select: function( event, ui ) {
                var terms = split( this.value );
                // remove the current input
                terms.pop();
                // add the selected item
                //replaced value with label to continue showing the names selected  
                terms.push( ui.item.label);
                //ui.item.valuethis is where my 
                // add placeholder to get the comma-and-space at the end
                terms.push( "" );
                this.value = terms.join( ", " );
                return false;


            }
        });
            $( "button" ).button();
        $( "button" ).click(function() {
        var selected_Text = $( "#tags" ).val();
        var selected_Friends = selected_Text.split(","); 
        //friend name put in the autocomplete box
        var friend_Name = "";
        //selected id of the person in the array 
                var testCount = 0; 
        //i < j --> run through interation once 
        for(var i = 0, j=selected_Friends.length; i<j; i++ )
        {
            friend_Name = selected_Friends[i];
            while (friend_Name[0] == " "){
                friend_Name = friend_Name.substring(1,friend_Name.length);
            }


            for (var k = 0, l = my_friends.length; k<l; k++)
            {

                if (friend_Name == my_friends[k]["label"])
                {
                    selected_Id.push(my_friends[k]["value"])

                    testCount++;

                } else {

                } 
            }
        }

        return false; 


    });
 });
  • 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-08T04:57:42+00:00Added an answer on June 8, 2026 at 4:57 am

    You could return an object of arrays:

    function someFunction() {
        return {
            enemies: [1, 2, 3],
            friends: [4, 5, 6]
        };
    }
    console.log(someFunction().enemies) //The array of [1,2,3]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm using autocomplete from jquery... and i have this: $('#name_search').autocomplete({ source: search/name.php, open: function(){
I have an input box for which I am using the Jquery autocomplete function.
I am using this plugin: http://jquery.bassistance.de/autocomplete/demo/ I have an autocomplete textarea where the values
I am using jQuery autocomplete pluggin . I have the following code $().ready(function() {
I have just built a custom autocomplete component using jquery. My problem is that
I'm using the jquery autocomplete function to enhance the user-friendliness of my site. It
i have an input using the jquery autocomplete plugin. with this i want to
I'm using jQuery 1.4.4 and jQuery UI 1.8.9. I have an autocomplete field that
using jquery I have a autocomplete text box like the combobox example on the
I have a textbox that is wired up using jQuery UI 1.8.4 autocomplete. I

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.