Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions 02_Day_Data_types/string_methods/accessing_character.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Let us access the first character in 'JavaScript' string.

let string = 'JavaScript'
let size = 0;
let firstLetter = string[0]
console.log(firstLetter) // J
let secondLetter = string[1] // a
Expand All @@ -10,3 +11,23 @@ console.log(lastLetter) // t
let lastIndex = string.length - 1
console.log(lastIndex) // 9
console.log(string[lastIndex]) // t

//Accessing String Value through loops
console.log("Iterating through for loop");
for(let i=0;i<string.length;i++){
console.log(string[i]);
}

console.log("Iterating through while loop");
while (size<string.length) {
console.log(string[size]);
size++;
}

console.log("Iterating through for-each");
[...string].forEach(j => console.log(j));

console.log("Iterating through for-of");
for(let m of string){
console.log(m);
}