Effecient Javascript Object filtering using multiple array indexes. How much data before using Node? -


i'm looking both practical, , theoretical insight application.

take 50,000 js objects, 5 properties each, structured as

0: object   costcenter: "1174"   country: "usa"   job: "110-article search"   team: "financial"   username: "anderson" 

and take 5 respective arrays (one each object property) such 'country' array

4: array[4]   0: "asia pacific"   1: "australia"   2: "brazil"   3: "canada" 

what efficient way filter 50,000 objects, eliminating objects have @ least 1 property has 0 matches in respective array.

the max sizes arrays are:

  costcenter,  77   country,     27   job,         27   team,        10   username,    99 

my first idea loop through 50,000 objects, ,

if 'costcenter' property === costcenter array item, push object temporary array of objects  

which might leave me 20,000 objects in temporary array. repeat process each property , respective filtering array, building new temporary object each time.

finally process leave me last array, resultant data after going through 5 filters.

it takes 20 seconds me download 18mb json file (but i'm okay that)

...which exponentially longer time takes chrome browser on 16gb ram process json 50,000 js objects , loop these objects dynamically build filtering arrays unique values contained in json.

is efficient? seems very fast amount of data being processed, feeling user environments (like boss' ipad) may run out of in-browser memory.

what better ways there?

should in node.js? javascript programmer, seems may not take long learn. plus node super duper hip these days... maybe should on it.

will browsers fail download 18mb json file? can find info limits?

basically want

var arrays = {     "country": […],     … }; var result = my50000items.filter(function(item) {     (var prop in arrays)         if (arrays[prop].indexof(item[prop]) == -1)              return false;     return true; }); 

you can optimise replacing indexof call faster property lookup. so, make:

var lookups = {}; (var prop in arrays) {     var obj = lookups[prop] = {};     (var i=0; i<arrays[prop].length; i++)         obj[arrays[prop][i]] = true; } 

then can use

var result = my50000items.filter(function(item) {     (var prop in lookups)         if (!lookups[prop][item[prop]])              return false;     return true; }); 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -