Skip to content

Instantly share code, notes, and snippets.

@inlanger
Created September 1, 2013 09:10
Show Gist options
  • Save inlanger/6403225 to your computer and use it in GitHub Desktop.
Save inlanger/6403225 to your computer and use it in GitHub Desktop.
Check if val in array and return new array with or without element.
function pushIfUnique(array, val){
var status = true;
for (var i = 0; i < array.length; i++) {
if (array[i]===val) {
status = false;
}
}
if (status){
array.push(val);
return array;
} else {
return array;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment