How to loop through an array of characters in TypeScript

2 Answers

0 votes
const array: string[] = ['a', 'b', 'c', 'd', 'e', 'f'];
  
for (let i in array) {
    console.log(array[i]);
}
 
 
 
 
/*
run:
  
"a"
"b"
"c"
"d"
"e" 
"f" 
  
*/

 



answered Sep 2, 2023 by avibootz
0 votes
const array: string[] = ['a', 'b', 'c', 'd', 'e', 'f'];
  
for (let i: number = 0; i < array.length; i++) {
    console.log(array[i]);
}

 
 
 
/*
run:
  
"a"
"b"
"c"
"d"
"e" 
"f" 
  
*/

 



answered Sep 2, 2023 by avibootz

Related questions

2 answers 173 views
4 answers 179 views
1 answer 146 views
2 answers 155 views
2 answers 168 views
1 answer 239 views
2 answers 101 views
101 views asked Oct 23, 2024 by avibootz
...