Skip to content

Instantly share code, notes, and snippets.

@wangwen1220
Last active January 4, 2016 13:29
Show Gist options
  • Select an option

  • Save wangwen1220/8628221 to your computer and use it in GitHub Desktop.

Select an option

Save wangwen1220/8628221 to your computer and use it in GitHub Desktop.
JS: 去掉 Javscript 数组中的重复元素 | contains
// 检查字符串中是否包含其他字符串
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] === obj) {
return i;
}
}
return -1;
}
}
if (!String.prototype.contains) {
String.prototype.contains = function(arg) {
return !!~this.indexOf(arg);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment