How to check if a string starts with specific character in TypeScript

1 Answer

0 votes
const s = "TypeScript";
const char = "T";

console.log(s.startsWith(char));

console.log(s.substring(0, 1) === char);

console.log(s.indexOf(char) === 0);

 
 
 
 
/*
run:
 
true
true
true
 
*/

 



answered Feb 13, 2022 by avibootz
...