-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.js
More file actions
36 lines (27 loc) · 771 Bytes
/
strings.js
File metadata and controls
36 lines (27 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//In JS strings behaves like arrays.
//eg:for loop over arrays.Arrays are iterable.
var letters = ["G","A","U","R","A","V"];
for (var i=0;i<letters.length;i++){
console.log(letters[i]);
}
//eg: for loop over string.Strings are iterable too..!!
var str = "GAURAV";
for(i=0;i<str.length;i++){
console.log(str[i]);
}
//string cheatsheet
//length property
var name1 ="Gaurav";
var sur1 = "Baral"
console.log(name1.length);
//To read each individual character at a specific index in a string, starting from zero, I can use the charAt() method:
console.log(name1.charAt(0));//G
//The concat() method joins two strings:
console.log(name1.concat(sur1));//GauravBaral
/*charAt()
concat()
indexOf()
lastIndexOf()
split()
toUpperCase()
toLowerCase() */