Skip to content

Commit

Permalink
fix indexOf code
Browse files Browse the repository at this point in the history
  • Loading branch information
hakeemsalman committed Nov 5, 2024
1 parent e4849a0 commit e85a1da
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ alert( 'Interface'[0].toLowerCase() ); // 'i'
- Parameters: `str.indexOf(string, pos)`
1. It looks for the `substr` in `str`, starting from the given position `pos`, and returns the position where the match was found or `-1` if nothing can be found.
```js
let str = 'Widget with id';
Expand All @@ -172,7 +173,7 @@ alert( str.indexOf('widget') ); // -1, not found, the search is case-sensitive
alert( str.indexOf("id") ); // 1, "id" is found at the position 1 (..idget with id)
```
2. The optional second parameter allows us to start searching from a given position.
1. The optional second parameter allows us to start searching from a given position.
```js
let str = 'Widget with id';
Expand Down Expand Up @@ -201,6 +202,7 @@ while ((pos = str.indexOf(target, pos + 1)) != -1) {
alert( pos );
}
```
3. Return value when using an empty search string
```js
Expand All @@ -213,7 +215,6 @@ while ((pos = str.indexOf(target, pos + 1)) != -1) {
"hello world".indexOf("", 13); // returns 11
```
### 2. str.lastIndexOf(substr, position)
- It searches from the end of a string to its beginning.
Expand Down

0 comments on commit e85a1da

Please sign in to comment.