get the third charecter in a string in javascript

To get the third character of a string in JavaScript, you can use the charAt() method. Here's an example:

index.tsx
const str = "hello";
const thirdChar = str.charAt(2); // index 2 represents the third character
console.log(thirdChar); // output: "l"
135 chars
4 lines

Alternatively, you can also use array notation to get the third character:

index.tsx
const str = "hello";
const thirdChar = str[2]; // index 2 represents the third character
console.log(thirdChar); // output: "l"
128 chars
4 lines

Both methods are equally valid and will produce the same result.

gistlibby LogSnag