I have one array like so:
peoples = ['dick', 'jane', 'harry', 'debra', 'hank', 'frank' .... ]
And one containing keys like so:
keys = [1, 6, 3, 12 .... ]
Now I could write something like this:
var peoplesStripedOfKeyPostions = [];
for(i = 0; i < peoples.length; i++){
for(j = 0; j < keys.length; j++){
if( i !== keys[j]){
peoplesStripedOfKeyPostions.push( peoples[i] );
}
}
}
If you can’t tell, I’m need to produce an array of people that is stripped of people at certain positions defined in array keys. I know there has to be a nifty and efficient way to do this, but I certainly can’t think of it. (array management not my forte).
Do you know a better way to do this? (If I get multiple working answers, jsperf determines the winner.)
This will become inefficient if the
badIndicesarray is large. A more efficient (albeit less elegant) version would be:(note: you cannot use a variable named
keysbecause that is a builtin function)