You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
functionfunc() {
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
+
functionfunc() {
38
+
39
+
// Original string
40
+
let str ='JavaScript is object oriented language';
0 commit comments