Home  >  Article  >  Web Front-end  >  Javascript's indexOf method to ignore case_javascript tips

Javascript's indexOf method to ignore case_javascript tips

WBOY
WBOYOriginal
2016-05-16 19:01:501769browse

Change them all into uppercase or lowercase, and then compare them
The character position of the first occurrence of the substring in the indexOf object
Use toLowerCase or toUpperCase


[Ctrl A Select All Note: If you need to introduce external Js, you need to refresh to execute
]

[Ctrl A Select All Note:
If you need to introduce external Js, you need to refresh to execute
]

Take a look at this, it’s compatible with the original indexOf
[Ctrl A select all Note: <script> var testStr = 'ABCDEF'; var subStr = 'bcd'; alert(testStr.toLowerCase().indexOf(subStr.toLowerCase())); testStr = 'AbCdEf'; alert(testStr.toLowerCase().indexOf(subStr.toLowerCase())); </script>If you need to introduce external Js, you need to refresh to execute <script> String.prototype.indexOf = function(f,m){ var mm = (m == false) ? "i":""; var re = eval("/"+ f +"/"+mm); var rt = this.match(re); return (rt == null) ? -1:rt.index; } var test = "absnegKIugfkalg"; alert(test.indexOf("kiu",false)); </script>]
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn