Skip to content

Commit fe8734f

Browse files
add: Example 4: Extract single character in Basic Usage substring()
1 parent 54c0141 commit fe8734f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

data/blog/software-development/web-development/frontend/javascript/slice-vs-substring-vs-substr-complete-javascript-string-methods-comparison.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ console.log(str.substring(4, 10)); // "Script"
368368
console.log(str.substring(4)); // "Script"
369369
// Explanation: When endIndex omitted, defaults to string.length
370370
// Equivalent to: str.substring(4, 10)
371+
372+
// Example 4: Extract single character
373+
console.log(str.substring(0, 1)); // "J"
374+
// Explanation: Start at 0, end before 1, so only index 0 is included
371375
```
372376

373377
#### Negative Indices (Always Treated as 0)

0 commit comments

Comments
 (0)