There are several possible approaches:
1) The straightforward:
function contains(array,element){
return array.indexOf(element)!=-1;
}
function filter(unfilteredArray){
var filteredArray=[];
for(var i=0; i<unfilteredArray.length; i+=1){
if(contains(omitted,unfilteredArray[i])) continue;
filteredArray.push(unfilteredArray[i]);
}
return filteredArray;
}
Looping over your array and sorting out, which ones you don't like.
You could play with this Fiddle
2) The "functional" approach
function omitting_1_to_10(element){
return [1,2,3,4,5,6,8,9,10].indexOf(element)==-1;
}
console.log([1,2,3,4,11].filter(omitting_1_to_10));
Define your omitting filter and apply it to your array.
For Array.filter
read the according MDN-article.
3) Doing it with a RegEx:
function filter(unfilteredArray){
var filteredArray=[];
for(var i in unfilteredArray){
if(/\b1\b|\b2\b|\b3\b|\b4\b|\b5\b|\b6\b|\b7\b|\b8\b|\b9\b|\b10\b/.test(unfilteredArray[i])) continue;
filteredArray.push(unfilteredArray[i]);
}
return filteredArray;
}
console.log(filter([1,2,3,4,11]));
Here is the Fiddle
if( wanting_to_skip_condition ) continue;
then the rest of the code you want run during a good loop. \$\endgroup\$if (keysToBeOmitted.Contains(key)) continue
. If you are concerned about performance then make sure yourkeysToBeOmitted
array is sorted and do a binary search on it (localCompare()
should help with that) \$\endgroup\$