Skip to content

Instantly share code, notes, and snippets.

@ultim8k
Last active September 12, 2018 10:44
Show Gist options
  • Save ultim8k/9e375fef439c3e241a7ad930f073b862 to your computer and use it in GitHub Desktop.
Save ultim8k/9e375fef439c3e241a7ad930f073b862 to your computer and use it in GitHub Desktop.
delete values from array | not optimised - who cares
var valuesToBeDeleted = [1, 5, 7, 15];
var mixedValues = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
// Boring solution:
valuesToBeDeleted.forEach(item => {
var itemIndex = mixedValues.indexOf(item);
mixedValues.splice(itemIndex, 1);
});
// Better solution:
var cleanValues = mixedValues.filter(item => valuesToBeDeleted.indexOf(item) < 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment