Note that there are some explanatory texts on larger screens.

plurals
  1. POLarge arrays & javascript comparison
    primarykey
    data
    text
    <p>So i have two very large multidimesional arrays(4000+). I get the first array as a response from the server where, i have to create dom nodes for each of these array elements. Once this process is finished i have to send another request where i will get another list of elements which will be a subset of the first list, based on the second list i have to modify some elements in the first list (and reflect these changes in the DOM as well). This process takes a very long time to finish, is there any way to accomplish this without two for loops? Or perhaps a faster comparison?</p> <p><strong>Scenario</strong></p> <blockquote> <p>The real world example would be as follows, consider a group of people in a particular area (arr1). In DOM this would be represented as <code>CheckBox - Name</code> Now consider a group of people who have been administered with a particular vaccine (arr2), Now arr2 has the list of elements for which the checkbox should be checked. The whole list(arr1's dom representation) has to be shown at all costs.</p> </blockquote> <p>Arrays are of the type </p> <pre><code>[ ["index", "name", "age"],............. ["4000-index", "4000-name", "4000-age"]] </code></pre> <p>Here is a pseudo code..</p> <pre><code>//First request, get the response (resp) and Create DOM elements accordingly for(var i=0, iLen=resp.length; i&lt;iLen; i++) { // Checkbox and &lt;span id='entry-"+resp[i][0]+"'&gt;resp[i][1]&lt;/span&gt; } // At a later stage in the code... //Request server for the second list get the response (resp) arr2 = resp // Second Array // Walk through the dom, get the list of span elements and store their ids in an array arr1 for(var i=0, iLen=arr1.length; i&lt;iLen; i++) { for(var j=0, jLen= arr2.length; j&lt;jLen; j++) { if(+arr2[j][0] === +arr1[i][0]) { //checkbox attr = 'checked' } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload