xxxxxxxxxx
Array.from('some string')[0];
xxxxxxxxxx
const string = 'Hello';
const firstCharacter = string.charAt(0);
console.log(firstCharacter);
xxxxxxxxxx
const str = "Hello world";
const firstChar = str.charAt(0); // Retrieves the first character of the string
console.log(firstChar); // Outputs 'H'
xxxxxxxxxx
# Function to get the first letter of a string
def get_first_letter(string):
if string: # Check if the string is not empty
return string[0] # Return the first character
else:
return None # Return None if the string is empty
# Example usage
word = "Hello"
first_letter = get_first_letter(word)
print(first_letter) # Output: H