Last active
January 4, 2016 13:29
-
-
Save wangwen1220/8628221 to your computer and use it in GitHub Desktop.
JS: 去掉 Javscript 数组中的重复元素 | contains
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 检查字符串中是否包含其他字符串 | |
| 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