Home > Web Front-end > JS Tutorial > JavaScript indexOf ignores case_javascript tips

JavaScript indexOf ignores case_javascript tips

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 18:55:14
Original
2022 people have browsed it

Let me introduce to you how to make the indexOf function in JavaScript ignore case.
Change them all into uppercase or lowercase, and then compare.
This is a relatively simple method!
The character position where the substring appears for the first time in the indexOf object.
Use toLowerCase or toUpperCase as follows:


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

Or look at the following How to extend the indexof function:

[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]
The following is compatible with the original indexOf Function, you can add the indexOf function operation that can be directly used to ignore case javascript.
[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>]
Related labels:
Statement of this Website
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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template