How do I trim all letter after the first letter?
e.g
var name = "Tony";
//output T
How do I trim all letter after the first letter?
e.g
var name = "Tony";
//output T
This not called a trim, this is a simple substring
:
console.log(name.substring(0, 1));
As suggested, you can also do
console.log(name[0]);
But this one will not works on old internet explorers (< IE7). This one will works everywhere too :
console.log(name.charAt(0));