Skip to content

Commit d6d091d

Browse files
Chandanmalisumn2u
andauthored
Added: charAt() method in string (#138)
* Create reverse.md Added reverse method --------- Co-authored-by: sumn2u <sumn2u@hotmail.com>
1 parent 4909649 commit d6d091d

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

en/strings/charAt.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
chapter: 4
3+
pageNumber: 30
4+
---
5+
# charAt()
6+
7+
str.charAt() returns the character at the given index of the string index holds the array element position.
8+
* using the `charAt()` method
9+
* using the template literal (introduced in ES6)
10+
11+
The charAt() method takes in:
12+
13+
Arguments: The only argument to this function is the index in the string from where the single character is to be extracted.
14+
15+
index: The range of this index is between 0 and length – 1. If no index is specified then the first character of the string is returned as 0 is the default index used for this function.
16+
Return Value: Returns a single character located at the index specified as the argument to the function. If the index is out of range, then this function returns an empty string.
17+
18+
```javascript
19+
//Example 1:
20+
function func() {
21+
// Original string
22+
let str = 'JavaScript is object oriented language';
23+
24+
// Finding the character at given index
25+
let value = str.charAt(0);
26+
let value1 = str.charAt(4);
27+
console.log(value);
28+
console.log(value1);
29+
}
30+
func();
31+
32+
//Output
33+
j
34+
s
35+
36+
//Example 2:
37+
function func() {
38+
39+
// Original string
40+
let str = 'JavaScript is object oriented language';
41+
42+
// Finding the character at given index
43+
let value = str.charAt(9);
44+
console.log(value);
45+
}
46+
func();
47+
48+
49+
//Output
50+
t

0 commit comments

Comments
 (0)