Improving script performance for looping unparalleled arrays Ive written a script to loop through a couple of unparalleled arrays a loop within a loop, Now im trying to find out if using break is all that's needed to exit and then continue over again.

What eles can you see or know to improve this?

var arr_vals = ["74","f4e3","22","r31","17","hundernds"]; // could have 500+ items
var arr_items = ["r31","22","65","100"]; // could have 50 items

var c = arr_items.length;
var arr_vals_len = arr_vals.length;
 for ( var i = 0; i &lt; c; i++ ) { 
   var xid = arr_items[i];

     for (var j = 0; j &lt; arr_vals_len; j++ ){
      if(arr_vals[j] === xid){
      // match !
      break;
}
 }
Instead of iterating through the inner array multiple times, it might be faster to create a map for the inner array beforehand and then test for a match within the map. (I think this will only work if they're arrays of strings, though.)

var arr_vals = ["74","f4e3","22","r31","17","hundernds"]; // could have 500+ items
var arr_items = ["r31","22","65","100"]; // could have 50 items

var vals_len = arr_vals.length;
var items_len = arr_items.length;

var map_items = {};
for(var j = 0; j &lt; items_len; ++j) {
  map_items[arr_items[j]] = 1;
}

for( var i = 0; i &lt; vals_len; ++i) {
  if(map_items[arr_vals[i]]) {
    // match!
  }
}


Perf test