How to check if a string starts with specific character in Node.js

1 Answer

0 votes
const s = "node.js";
const char = "n";

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

Related questions

...