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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:06:35+00:00 2026-05-23T13:06:35+00:00

In order to build the array of strings necessary for JQuery autocomplete, I’m traversing

  • 0

In order to build the array of strings necessary for JQuery autocomplete, I’m traversing an array of objects and flattening it into an array of unique strings. I’m doing this about how you might expect:

var input = [{prop1:'value1', prop2: 'value2'}];

 $.each(input, function (index, value) {
                $.each(value, function (i, v) {
                    if (v != undefined && v != null && v != '' && ($.inArray(v, keywords) < 0)) {
                        keywords.push(v);
                    }
                });
            });

The problem is that it performs poorly for large input sets, and blocks the UI while it’s running. How can I make this better?

  • 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-23T13:06:36+00:00Added an answer on May 23, 2026 at 1:06 pm

    You’ve got an O(n^2) algorithm there. Looking through that keywords array over and over again is going to get really slow (as you’ve noticed).

    Instead, keep the keywords as an object:

    var keywords = {};
    
        // ... inside your ".each():
        if (v && !keywords[v])
          keywords[v] = true;
    

    Note that your tests of “v” against undefined, null, and the empty string can be replaced by letting JavaScript check it’s truthiness. That’s not always the right thing, but it’s fine here.

    You can also keep the keywords in an array, if you like. Just don’t search the array to determine whether a keyword has been seen yet.

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

Sidebar

Related Questions

I got this code in order to build an url for the link using
I've been following this tutorial (lesson 6) in order to build and deploy a
I'm starting research on what I'd need in order to build a user-level plugin
Just thinking about the best way to build an Order form that would (from
I normally build my solution with MSBuild in order to keep Visual Studio responsive
I need to compare build outputs of VS2005 in order to be sure I
On our build server, we've installed the .NET Framework 2.0 SDK in order to
I'm trying to build an efficient string matching algorithm. This will execute in a
So I build an array of various dates. Birthdays, anniversaries, and holidays. I'd like
I am trying to build a function in C/C++ to sort an array and

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.