What would be the fastest way of skipping certain values in a for loop? This is what I intend to do in its most basic form, with about 20 more keys to omit.for (var key in arr ) {    if ( key != 'ContentType' && key != 'FileRef' ) {        arrayPushUnknown( columns, formatTitle( key ), true, key )    }   }   
Optimal way of skipping certain values in a for loop
javascript;performance
One of the simplest and probably fastest way to do it would be to store the keys to ignore in a fast lookup structure, such as using an object as a map.First you need to build the map, which takes O(n) time based on the number of keys to ignore, but allows you to ignore keys with a condition that will take O(1) time to compute.var keysToIgnore = ['ContentType', 'FileRef'].reduce(function (res, key) {    res[key] = true;    return res;}, {});Then within the loop, if the key should be ignored, just continue.if (keysToIgnore[key]) continue;The algorithm will probably not be an order of magnitude faster (slower? could be!) than a bunch of ifs or a switch statement, but it will definitely be more readable. It also has the advantage of being dynamic, since you can add or remove keys from keysToIgnore.Note: If you have to perform the iteration process many times, it could be faster to simply filter out the keys using Array.prototype.filter and the algorithm described above.