find the first character in a string in javascript

You can find the first character in a string in JavaScript by using the charAt() method or by accessing the string like an array. Here are two examples:

Using charAt() method:

index.tsx
const str = 'hello';
const firstChar = str.charAt(0);
console.log(firstChar); // Output: 'h'
93 chars
4 lines

Accessing the string like an array:

index.tsx
const str = 'hello';
const firstChar = str[0];
console.log(firstChar); // Output: 'h'
86 chars
4 lines

gistlibby LogSnag