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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:27:08+00:00 2026-05-27T16:27:08+00:00

I have a array of data ,let us say var products =[]; products array

  • 0

I have a array of data ,let us say var products =[]; products array will contains 10000 elements
Now i just want to find out all the products which is having name item1 .
In this case which one is efficient(in case of performace) making an ajax call to server to get the items with name item1, or Loop through products 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-27T16:27:08+00:00Added an answer on May 27, 2026 at 4:27 pm

    Personally I wouldn’t recommend you to keep 10000 elements in browser.

    You can do a simple test to see how much memory it will take. I’ll explain it with Chrome browser.
    Open blank page, hit F12 to open developer tools and go to ‘Profiles’ tab. Then simply click on the ‘eye’ icon on the bottom – you will see new memory snapshot on left. When you click its size will appear under its name. Next go to ‘Console’ tab and run this code:

    var products = {};
    for (var i = 10000; i--; ) {
        products['name' + i] = {
            id             : i, 
            description    : (new Array(201)).join('x')
        };
    }
    

    Then return to the ‘Profiles’ tab and take second snapshot with ‘eye’ icon. When you compare their size you will see how much memory this simple objects took. In my case it is about 3MB and this are simple objects only with two fields: id and 200 chars of description. If you would have more complicated objects it would take much more. Of course it would be better if you would use objects similar to your to see how it would look like.

    Second thing is that if you decide to use them in browser you have send all of them to it. So with simple objects like above even when you strip unnecessary whitespaces and single object will look like this:

    p['namex']={id:x,description:'200 chars here....'};
    

    and it will take about 250 chars per one entry, so with 10 000 entries you will send about 250 x 10 000 = 2 500 000 chars which is approximately about 2.5MB. And you will send this to client on every page reload/refresh.

    Third point: if you would like to do searching by name (as you wrote in your question) you can’t use javascript object to this – objects with the same name overwrite predecessors. In this case you should rather use simple array. Moreover even if names would be different and you would like to search names which contains some string, e.g. you have this data

    products['item1']     = {/** some data */};
    products['foo']       = {/** some data */};
    products['item13']    = {/** some data */};
    products['bar']       = {/** some data */};
    products['xitem1']    = {/** some data */};
    

    and you would like to find all products which contains word ‘item’ you should use array instead of object because iterating over array is faster than iterating on object with for .. in loop (moreover iterating on array in reverse order is also quite faster than in standard order).

    When it comes to server side searching there is also a lot of things to consider – performance can depend on many factors like your backend technology (language, database) and also can be boosted by e.g. memcached or redis which should give you really good time of response, and I’m sure that this would be better than sending all data from database to client on each request and dealing with it in browser 🙂

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

Sidebar

Related Questions

Let say I have an array like: Array ( [0] => Array ( [Data]
i have wrote a script to produce an array of data but now want
Let's say you have a JavaScript class like this var DepartmentFactory = function(data) {
Let's say we have data as follows var data = { facets: [{ name
Let's say, I want to separate certain combinations of elements from an array. For
Let's say I have a tab-delimited text file that contains data arranged in columns
Say you have an array, data, of unknown length. Is there a shorter method
I have a string say string s =C:\\Data , I have an array which
Let's say I have an array k = [1 2 0 0 5 4
Let's say that I have string: -dog--cat--d-- I would like to find all words

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.